📜  获取扩展类 c# 代码示例的所有类

📅  最后修改于: 2022-03-11 14:48:45.299000             🧑  作者: 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;
    }
}