Something like:
public static IEnumerable<Type> GetSubtypes(Assembly assembly, Type parent) { return assembly.GetTypes() .Where(type => parent.IsAssignableFrom(type)); }
This is good for a simple case, but it becomes more "interesting" (read: difficult) when you want to find "all types that implement IEnumerable<T> for any T ", etc.
(As Adam says, you can easily do this with an extension method. It depends on whether you think you are reusing it or not - this is a pain that extension methods should be in a non-nested static class ...)
Jon skeet
source share