开发者

C# - How to get certain generic types from an assembly using linq

I'm trying to find types in an assembly that are of ISomeInterface< AnyType > using linq.

How do I do this?

Here's what I have:

开发者_JAVA百科AppDomain.CurrentDomain.GetAssemblies().SelectMany(a=>a.GetTypes().Where(t=> /* t is ISomeInterface<ofAnyType> */))


Something like (I'm not at a pc)

from asm in AppDomain.CurrentDomain.GetAssemblies()
from type in asm.GetTypes()
where (type.IsClass || type.IsStruct)
  && type.GetInterfaces().Any(
  intf => intf.IsGenericType
    && intf.GetGenericTypeDefinition() == typeof(ISomeInterface<>))
select type;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜