Thursday, August 5, 2010

C#: How to get all the classes that inherits from a specific type

Code snippet for getting all the classes that inherits from a specific type:

public IList GetAllDerivedClasses(Type baseType)
{
 return baseType.Assembly.GetTypes().Where(
  x => 
   x.IsClass
   && x.IsSubclassOf(baseType)).ToList();
}