views:

42

answers:

1

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:

AppDomain.CurrentDomain.GetAssemblies().SelectMany(a=>a.GetTypes().Where(t=> /* t is ISomeInterface<ofAnyType> */))
+1  A: 

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;
Marc Gravell