开发者

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

开发者 https://www.devze.com 2023-01-16 13:02 出处:网络
I\'m trying to find types in an assembly that are of ISomeInterface< AnyType >using linq. How do I do this?

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

精彩评论

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