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     }
复制代码
复制代码
     public  static  bool IsRealClass(Type testType)
    {
         return testType.IsAbstract ==  false
            && testType.IsGenericTypeDefinition ==  false
            && testType.IsInterface ==  false;
    }
复制代码
本文转自today4king博客园博客,原文链接:http://www.cnblogs.com/jinzhao/archive/2011/12/15/2288885.html,如需转载请自行联系原作者
相关文章
|
14天前
|
C#
57.c#:directorylnfo类
57.c#:directorylnfo类
16 0
|
8月前
|
C++
C++的类
C++的类
|
14天前
|
传感器 存储 调度
PowerManagerService类大致解读
PowerManagerService类大致解读
20 1
|
14天前
深入类的方法
深入类的方法
11 0
|
14天前
|
Java
JAVASystem类
JAVASystem类
9 0
注解与反射6得到Class类的几种方式
注解与反射6得到Class类的几种方式
|
Java
Java - 反射使用(调用私有方法、修改私有属性、获取父类私有字段)
Java - 反射使用(调用私有方法、修改私有属性、获取父类私有字段)
731 0
TimeUnit类详解
TimeUnit类详解
258 0
TimeUnit类详解
13.3.1 QBluetoothSocket类介绍
13.3.1 QBluetoothSocket类介绍
110 0
13.3.1 QBluetoothSocket类介绍
|
存储 开发框架 自然语言处理
最全面Enumerable类的实用总结
最全面Enumerable类的实用总结
295 0
最全面Enumerable类的实用总结

热门文章

最新文章