且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Implementations of interface through Reflection 反射根据继承的信息查找指定的类

更新时间:2022-09-15 23:23:22

Implementations of interface through Reflection 反射根据继承的信息查找指定的类
 1     /// <summary>
 2     /// Returns all types in the current AppDomain implementing the interface or inheriting the type. 
 3     /// </summary>
 4     public static IEnumerable<Type> TypesImplementingInterface(Type desiredType)
 5     {
 6         return AppDomain
 7             .CurrentDomain
 8             .GetAssemblies()
 9             .SelectMany(assembly => assembly.GetTypes())
10             .Where(type => desiredType.IsAssignableFrom(type));
11 
12     }
Implementations of interface through Reflection 反射根据继承的信息查找指定的类
Implementations of interface through Reflection 反射根据继承的信息查找指定的类
    public static bool IsRealClass(Type testType)
    {
        return testType.IsAbstract == false
            && testType.IsGenericTypeDefinition == false
            && testType.IsInterface == false;
    }
Implementations of interface through Reflection 反射根据继承的信息查找指定的类
本文转自today4king博客园博客,原文链接:http://www.cnblogs.com/jinzhao/archive/2011/12/15/2288885.html,如需转载请自行联系原作者