📜  c# 获取继承的类 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:52.728000             🧑  作者: Mango

代码示例1
public static class ReflectiveEnumerator
{
    static ReflectiveEnumerator() { }

    public static IEnumerable GetEnumerableOfType(params object[] constructorArgs) where T : class, IComparable
    {
        List objects = new List();
        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;
    }
}