Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# get all inherited classes of a class

//through reflection
using System.Reflection;

//as a reusable method/function
Type[] GetInheritedClasses(Type MyType) 
{
  	//if you want the abstract classes drop the !TheType.IsAbstract but it is probably to instance so its a good idea to keep it.
	return Assembly.GetAssembly(MyType).GetTypes().Where(TheType => TheType.IsClass && !TheType.IsAbstract && TheType.IsSubclassOf(MyType));
}

//or as a selection of a type in code.
Type[] ChildClasses Assembly.GetAssembly(typeof(YourType)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(YourType))));

//Example of usage
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));
            }
Comment

PREVIOUS NEXT
Code Example
Csharp :: wann war der dritte weltkrieg 
Csharp :: c# print to console 
Csharp :: unity run void from another script 
Csharp :: set player position unity 
Csharp :: how to do a foreach loop in c# for dictionary 
Csharp :: detecting a right click unity 
Csharp :: how to get the directory of the project in c# 
Csharp :: json stringify c# 
Csharp :: core Request.CreateResponse 
Csharp :: C# previous method 
Csharp :: c# convert string to double 
Csharp :: sconvert string to title case + C3 
Csharp :: create folder in appdata c# 
Csharp :: unity inspector how to get larger field for string text 
Csharp :: how o remove .meta files visual studio code 
Csharp :: how to play video in ui unity 
Csharp :: wpf choose file dialog 
Csharp :: How to read StreamReader text line by line 
Csharp :: how to write blank lines in c#.net 
Csharp :: unity how to wait for seconds without coroutine 
Csharp :: messagebox.show c# error 
Csharp :: base64decode C# 
Csharp :: c# socket receive 
Csharp :: Considerando um projeto C# e o uso do Entity Framework, após realizar uma alteração em um registro, qual o método que deve ser chamado para salvar as 
Csharp :: unity system time 
Csharp :: socket would block error c# 
Csharp :: C# data table primary key from 2 columns 
Csharp :: remove session in dotnet core 
Csharp :: c# convert enum to list 
Csharp :: unity iterate all child objects 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =