get all subclasses c# code example
Example 1: 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));
}
Example 2: c# get list of all class fields
using System.Reflection;
FieldInfo[] property_infos = typeof(Player).GetFields();