Car*_*erg 11 c# reflection inheritance assemblies
class Foo { }
class Foo1 : Foo { }
class Foo2 : Foo { }
Run Code Online (Sandbox Code Playgroud)
我怎样才能将所有使用Foo的类作为基类?在同一程序集中不需要继承的类.
Sam*_*ell 16
这不是很快,但只要Foo
是具体类型(不是接口),它应该工作.Foo
本代码不返回本身.
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(Foo)));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6400 次 |
最近记录: |