For example if I wanted to see what my .NET options were for something implementing IList or IDictionary. Is there a way to find that for example in the MSDN documentation?
5 Answers
-
Search for the interface in Reflector, and then expand the Derived Types under that interface. – Don Kirkby Jul 15 '09 at 21:50
-
Make sure you tell Reflector about all the assemblies that you are using. Otherwise, it won't be able to find those implementations. – Daniel Yankowsky Jul 20 '09 at 14:46
To find it in MSDN, I usually go to Google, type something like "MSDN IList", and to get to IList Interface which has a section "Classes that Implement IList". That's true for any of the interface classes.
If you find a base class such as DictionaryBase, there will be a link called Derived Classes which will take you to a tree showing the inheritance hierarchy.

- 23,931
- 5
- 55
- 71
You can also do this programmatically.
If you know the assembly where the types are located (I'm using mscorlib
as that is where string
is located) you can build a list using this method:
.Net 3.0
List<Type> implementors =
Assembly.GetAssembly(typeof(string))
.GetTypes()
.Where(type => type.GetInterfaces().Contains(typeof(IList)))
.ToList();
.Net 2.0
List<Type> implementors = new List<Type>();
foreach (Type type in Assembly.GetAssembly(typeof(string)).GetTypes())
{
foreach (Type interfaceType in type.GetInterfaces())
{
if (interfaceType == typeof(IList))
{
implementors.Add(type);
}
}
}
The implementors
list will hold a list of of Types
that implement the interface IList
. You can change IList
to any interface you'd like, IDictionary
, ICollection
, etc.
Edit:
If you want to extend this to all assemblies in the current AppDomain
, you could do:
List<Type> implementors =
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes()
.Where(type => type.GetInterfaces().Contains(typeof(IList)))
).ToList();
It really all depends on what you're doing with the data. If you just want to view them for your own personal satisfaction, Reflector is going to be your easiest option - especially if you want to look beyond assemblies loaded in your application domain (assuming you have an application to begin with). I suppose you could load all the assemblies from the GAC in that case... but this is basically what Reflector does except you get to pick and choose which ones you want individually.

- 62,489
- 19
- 106
- 139
-
Would be more difficult if having to take other assemblies into account as well... or are there a way of scanning through all assemblies that are considered part of the .Net Framework? – Svish Jul 15 '09 at 23:40
You can lookup the interfaces a certain type implements with this method:
http://msdn.microsoft.com/en-us/library/system.type.getinterfaces.aspx
Should do the trick

- 5,065
- 23
- 24
-
I think the question was asking for the opposite: all classes that implement a certain interface. – Don Kirkby Jul 15 '09 at 21:48
-
Do you have a specific use case? Off the top of my head you could use:
System.Collections.ArrayList (or derived)
System.Collections.ObjectModel.Collection<T> derived
System.Collections.CollectionBase derived
System.Collections.DictionaryBase derived
System.Collections.Hashtable (or derived)

- 97,721
- 20
- 209
- 280