Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

get all classes that extend a class c#

public static class ReflectiveEnumerator
{
    static ReflectiveEnumerator() { }

    public static IEnumerable<T> GetEnumerableOfType<T>(params object[] constructorArgs) where T : class, IComparable<T>
    {
        List<T> objects = new List<T>();
        foreach (Type type in 
            Assembly.GetAssembly(typeof(T)).GetTypes()
            .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
        {
            objects.Add((T)Activator.CreateInstance(type, constructorArgs));
        }
        objects.Sort();
        return objects;
    }
}
Comment

get all classes that extend a class c#

public static class ReflectiveEnumerator
{
    static ReflectiveEnumerator() { }

    public static IEnumerable<T> GetEnumerableOfType<T>(params object[] constructorArgs) where T : class, IComparable<T>
    {
        List<T> objects = new List<T>();
        foreach (Type type in 
            Assembly.GetAssembly(typeof(T)).GetTypes()
            .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
        {
            objects.Add((T)Activator.CreateInstance(type, constructorArgs));
        }
        objects.Sort();
        return objects;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: replace first occurrence of character in string c# 
Csharp :: unity tilemap get all tiles 
Csharp :: c# xml get root attributes 
Csharp :: string to char array c# 
Csharp :: how to evaluate code in c# 
Csharp :: unity game object remove parent 
Csharp :: c# max two values 
Csharp :: wasd code for unity 
Csharp :: input field to float unity 
Csharp :: entity framework core db first 
Csharp :: .net 6 autofac 
Csharp :: c# foreach namevaluecollection 
Csharp :: c# count directories in directory and subdirectories 
Csharp :: how to trim path in C# 
Csharp :: #ifdef in c 
Csharp :: c# list item not in another list 
Csharp :: why is called c# 
Csharp :: check if mouse is in frame unity 
Csharp :: c# const vs readonly 
Csharp :: c# iterate sorteddictionary 
Csharp :: c# round to closest multiple 
Csharp :: change size of button c# 
Csharp :: remove scenedelegate 
Csharp :: edit list element linq c# 
Csharp :: drop down list razor example 
Csharp :: c# array zaheln speichern 
Csharp :: C# Blocks with statements 
Csharp :: clickable table row asp.net core 
Csharp :: How to create a Blazor server-side application in command prompt 
Csharp :: how to get relative path in c# 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =