4

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?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Svish
  • 152,914
  • 173
  • 462
  • 620

5 Answers5

5

I think it's possible using Reflector

Sorantis
  • 14,496
  • 5
  • 31
  • 37
3

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.

lavinio
  • 23,931
  • 5
  • 55
  • 71
3

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.

John Rasch
  • 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
1

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

Henri
  • 5,065
  • 23
  • 24
0

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)
Sam Harwell
  • 97,721
  • 20
  • 209
  • 280