get all child classes of a class b C# code example
Example: C# get all child classes of a class
using System.Reflection;
Type[] GetInheritedClasses(Type MyType)
{
return Assembly.GetAssembly(MyType).GetTypes().Where(TheType => TheType.IsClass && !TheType.IsAbstract && TheType.IsSubclassOf(MyType));
}
Type[] ChildClasses Assembly.GetAssembly(typeof(YourType)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(YourType))));
foreach (Type Type in
Assembly.GetAssembly(typeof(BaseView)).GetTypes()
.Where(TheType => TheType.IsClass && !TheType.IsAbstract && TheType.IsSubclassOf(typeof(BaseView))))
{
AddView(Type.Name.Replace("View", ""), (BaseView)Activator.CreateInstance(Type));
}