Find all classes that inherit a certain class

Published 25 May 2009

In some situations, it may be handy to retrieve all classes that inherit a certain base class.

This is by no means hard, but perhaps a bit obscure:

public static IEnumerable<Type> GetClasses(Type baseType)
{
    var assembly = Assembly.GetCallingAssembly();
    return assembly.GetTypes().Where(type => type.IsSubclassOf(baseType));
}

Hope this helps.