如何获取基类的所有inheritance类?

class Foo { } class Foo1 : Foo { } class Foo2 : Foo { } 

我怎样才能获得所有使用Foo作为基类的类? 在同一程序集中不需要inheritance的类。

这并不快,但只要Foo是具体类型(不是接口),它就应该有效。 此代码不返回Foo本身。

 AppDomain.CurrentDomain.GetAssemblies() .SelectMany(assembly => assembly.GetTypes()) .Where(type => type.IsSubclassOf(typeof(Foo)));