4.0 .NET Framework中的所有通用集合/类型是什么?

时间:2010-11-29 21:13:29

标签: c# .net vb.net generics .net-4.0

4.0 .NET Framework中是否存在所有“基础”(在面向对象的意义上没有使用但在常识中更常用)泛型类型的详尽列表?我发现this list我经常发送更新/中级开发人员,以便他们能够理解非泛型类型如何映射到泛型类型,但这绝不是详尽无遗的。我正在寻找的东西还包括KeyValuePair<>Tuple<>以及其他可能不为人所知的基本泛型。诸如IObservable<>之类的接口会很好但不一定是必需的。

6 个答案:

答案 0 :(得分:7)

这是一个powershell片段,列出了系统程序集中的所有泛型类型

[AppDomain]::CurrentDomain.GetAssemblies() | 
    ? { $_.FullName -match "^System" -or $_.FullName -match "mscorlib"} |  
        % { $_.GetTypes() | ? { $_.ContainsGenericParameters } }

这可以用来提供更全面的清单。如果您加载powershell w/ a .Net 4 config,则会获得4.0列表。

Count Name                      
----- ----                      
    1 System.Xml
   12 System.Data
   67 System
  187 mscorlib
  325 System.Core

答案 1 :(得分:4)

在Visual Studio中打开对象资源管理器,选择“.NET 4 Framework”,搜索IEnumerable<T>并展开派生类型列表。粘贴在这里太多了: - )。

alt text

答案 2 :(得分:3)

您可以反思所有BCL程序集并使用IsGenericType方法获取泛型类型列表。

答案 3 :(得分:2)

您可以在System.Collections.Generic命名空间中找到它 http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx

答案 4 :(得分:2)

这应该给你一些答案:

  1. System.Collections.Generic Namespace
  2. System.Collections.Concurrent Namespace 即可。
  3. System.Collections.Generic 命名空间提供了我们从.NET 3.5中已经知道的大多数通用集合。已经提供了三个线程安全的集合:

    System.Collections.Concurrent 命名空间命名空间提供了线程安全的通用集合。

答案 5 :(得分:2)

这是我的代码。根据需要添加更多组件。

    static void Main(string[] args)
    {
        Assembly[] assemblies = new Assembly[] { 
            typeof(string).Assembly,
            typeof(Uri).Assembly, 
            typeof(System.Linq.Enumerable).Assembly};

        List<string> final = new List<string>();

        Debug.WriteLine("Checked assemblies: ");
        foreach (Assembly assembly in assemblies)
        {
            Debug.WriteLine(assembly.FullName);

            Type[] types = assembly.GetTypes();
            IEnumerable<Type> genericTypes = types.Where(t => t.IsGenericType && t.IsPublic);
            foreach (Type t in genericTypes)
            {
                final.Add(t.FullName);
            }
        }

        final.Sort();

        Debug.WriteLine("Generic classes: ");
        foreach (string s in final)
        {
            Debug.WriteLine(s);
        }
    }

结果:

  • 已检查的程序集:
  • mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089
  • System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089
  • System.Core,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089

  • 通用课程:

  • System.Action`1
  • System.Action`10
  • System.Action`11
  • System.Action`12
  • System.Action`13
  • System.Action`14
  • System.Action`15
  • System.Action`16
  • System.Action`2
  • System.Action`3
  • System.Action`4
  • System.Action`5
  • System.Action`6
  • System.Action`7
  • System.Action`8
  • System.Action`9
  • System.ArraySegment`1
  • System.Collections.Concurrent.BlockingCollection`1
  • System.Collections.Concurrent.ConcurrentBag`1
  • System.Collections.Concurrent.ConcurrentDictionary`2
  • System.Collections.Concurrent.ConcurrentQueue`1
  • System.Collections.Concurrent.ConcurrentStack`1
  • System.Collections.Concurrent.IProducerConsumerCollection`1
  • System.Collections.Concurrent.OrderablePartitioner`1
  • System.Collections.Concurrent.Partitioner`1
  • System.Collections.Generic.Comparer`1
  • System.Collections.Generic.Dictionary`2
  • System.Collections.Generic.EqualityComparer`1
  • System.Collections.Generic.HashSet`1
  • System.Collections.Generic.ICollection`1
  • System.Collections.Generic.IComparer`1
  • System.Collections.Generic.IDictionary`2
  • System.Collections.Generic.IEnumerable`1
  • System.Collections.Generic.IEnumerator`1
  • System.Collections.Generic.IEqualityComparer`1
  • System.Collections.Generic.IList`1
  • System.Collections.Generic.ISet`1
  • System.Collections.Generic.KeyValuePair`2
  • System.Collections.Generic.LinkedList`1
  • System.Collections.Generic.LinkedListNode`1
  • System.Collections.Generic.List`1
  • System.Collections.Generic.Queue`1
  • System.Collections.Generic.SortedDictionary`2
  • System.Collections.Generic.SortedList`2
  • System.Collections.Generic.SortedSet`1
  • System.Collections.Generic.Stack`1
  • System.Collections.ObjectModel.Collection`1
  • System.Collections.ObjectModel.KeyedCollection`2
  • System.Collections.ObjectModel.ObservableCollection`1
  • System.Collections.ObjectModel.ReadOnlyCollection`1
  • System.Collections.ObjectModel.ReadOnlyObservableCollection`1
  • System.Comparison`1
  • System.ComponentModel.BindingList`1
  • System.Converter`2
  • System.EventHandler`1
  • System.Func`1
  • System.Func`10
  • System.Func`11
  • System.Func`12
  • System.Func`13
  • System.Func`14
  • System.Func`15
  • System.Func`16
  • System.Func`17
  • System.Func`2
  • System.Func`3
  • System.Func`4
  • System.Func`5
  • System.Func`6
  • System.Func`7
  • System.Func`8
  • System.Func`9
  • System.IComparable`1
  • System.IEquatable`1
  • System.IObservable`1
  • System.IObserver`1
  • System.Lazy`1
  • System.Linq.EnumerableExecutor`1
  • System.Linq.EnumerableQuery`1
  • System.Linq.Expressions.Expression`1
  • System.Linq.IGrouping`2
  • System.Linq.ILookup`2
  • System.Linq.IOrderedEnumerable`1
  • System.Linq.IOrderedQueryable`1
  • System.Linq.IQueryable`1
  • System.Linq.Lookup`2
  • System.Linq.OrderedParallelQuery`1
  • System.Linq.ParallelQuery`1
  • System.Nullable`1
  • System.Predicate`1
  • System.Runtime.CompilerServices.CallSite`1
  • System.Runtime.CompilerServices.ConditionalWeakTable`2
  • System.Runtime.CompilerServices.ReadOnlyCollectionBuilder`1
  • System.Runtime.CompilerServices.RuleCache`1
  • System.Runtime.CompilerServices.StrongBox`1
  • System.Security.AccessControl.AccessRule`1
  • System.Security.AccessControl.AuditRule`1
  • System.Security.AccessControl.ObjectSecurity`1
  • System.Threading.Tasks.Task`1
  • System.Threading.Tasks.TaskCompletionSource`1
  • System.Threading.Tasks.TaskFactory`1
  • System.Threading.ThreadLocal`1
  • System.Tuple`1
  • System.Tuple`2
  • System.Tuple`3
  • System.Tuple`4
  • System.Tuple`5
  • System.Tuple`6
  • System.Tuple`7
  • System.Tuple`8