Dan*_*nor 0 .net c# reflection
这是对这个问题的姐妹问题
如果我有一个实例
System.Reflection.Assembly
Run Code Online (Sandbox Code Playgroud)
我有以下型号:
class Person {}
class Student : Person {}
class Freshman : Student {}
class Employee : Person {}
class PersonList : ArrayList {}
class StudentList : PersonList {}
Run Code Online (Sandbox Code Playgroud)
如何枚举程序集的类型以获取对Employee,Freshman和StudentList的引用?
我希望能够枚举任何给定程序集的所有底部类型,如上例所示.
谢谢你的时间 :)
所以你想找到程序集中没有其他类型派生的所有类型,对吧?
(为了便于阅读而重新考虑.)
var allTypes = assembly.GetTypes();
var baseTypes = allTypes.Select(type => type.BaseType);
var bottomTypes = allTypes.Except(baseTypes);
Run Code Online (Sandbox Code Playgroud)
(如果你想要一个.NET 2.0版本,请告诉我.它会有点痛苦.)
归档时间: |
|
查看次数: |
102 次 |
最近记录: |