您的位置:首页 > 其它

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

2011-12-15 14:45 232 查看
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())

.Where(type => desiredType.IsAssignableFrom(type));

}

public static bool IsRealClass(Type testType)
{
return testType.IsAbstract == false
&& testType.IsGenericTypeDefinition == false
&& testType.IsInterface == false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐