我正在尝试在ISomeInterface<组件中找到类型。 AnyType>使用linq。
我该怎么做?
这就是我所拥有的:
AppDomain.CurrentDomain.GetAssemblies().SelectMany(a=>a.GetTypes().Where(t=> /* t is ISomeInterface<ofAnyType> */))
答案 0 :(得分:2)
像(我不在电脑里)
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;