2

Is there an exhaustive list of all of the "base" (not used in an object-oriented sense but more in a common sense) generic types in the 4.0 .NET Framework? I have found this list that I often send newer/mid-level devs to so they can understand how non-generic types map to generic types, but this is by no means exhaustive. I'm looking for something that also includes things such as KeyValuePair<>, Tuple<>, and other basic generics that may not be very-well known. Interfaces such as IObservable<> would be nice but not necessarily required.

Jaxidian
  • 13,081
  • 8
  • 83
  • 125
  • Maybe we could write all the generics we suppose useful as answers below? And you would generate list of types from answers? – The Smallest Nov 29 '10 at 21:16
  • Unfortunately, what you're asking for needs to be better defined. `KeyValuePair<>` and `Tuple<>` aren't collection types (though `KeyValuePair` is closely associated with `Dictionary<>`). `IObservable` is also not a collection interface, though `ObservableCollection` does make use of it. Do you want types like `IQueryable`, which don't represent a collection but a repository (of undefined size) that you can run queries against? – Adam Robinson Nov 29 '10 at 21:30

6 Answers6

7

Here's a powershell fragment to list all the generic types in the system assemblies

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

This could be adapted to give a more comprehensive list. If you load powershell w/ a .Net 4 config, you'll get the 4.0 list.

Count Name                      
----- ----                      
    1 System.Xml
   12 System.Data
   67 System
  187 mscorlib
  325 System.Core
Community
  • 1
  • 1
Scott Weinstein
  • 18,890
  • 14
  • 78
  • 115
4

In Visual Studio open the object explorer, choose .NET 4 Framework, search for IEnumerable<T> and expand the list of derived types. It's way too much to paste here :-).

alt text

VVS
  • 19,405
  • 5
  • 46
  • 65
3

You could reflect on all the BCL assemblies and use the IsGenericType method to get a list of generic types.

SpeksETC
  • 1,003
  • 2
  • 7
  • 13
2

You can find this in the System.Collections.Generic namespace http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx

Shiv Kumar
  • 9,599
  • 2
  • 36
  • 38
2

This should give you some answers:

  1. System.Collections.Generic Namespace;
  2. System.Collections.Concurrent Namespace.

The System.Collections.Generic namespace provides most of the generic collections that we already know from .NET 3.5. There was already providing three thread-safe collections:

The System.Collections.Concurrent namespace namespace provides thread-safe generic collections.

Will Marcouiller
  • 23,773
  • 22
  • 96
  • 162
2

Here's my code. Add more assemblies as you desire.

    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);
        }
    }

Results:

  • Checked assemblies:
  • 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

  • Generic classes:

  • 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
David Yaw
  • 27,383
  • 4
  • 60
  • 93