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;
精彩评论