如何使用反射从我的Assembly中使用派生类获取基类名称 [英] How to get Baseclass name using derived class from my Assembly using Reflection
问题描述
我有一个程序集,并且正在从该程序集中获取所有类.
遍历所有类时,如何使用反射获取当前类的基类名称.
您可以使用Type.BaseType来获取基类类型: http://msdn.microsoft.com/en-us/library/system.type.basetype.aspx
如果您要获取基类名称,它将类似于:
Type classType = typeof(YourClass); 类型baseType = classType.BaseType; 字符串baseClassName = baseType.Name;请注意,如果递归搜索基本类型,则在typeof(System.Object)上调用BaseType时,将得到null.
Hi,
I have an assembly and I am getting all classes from my assembly.
When looping through all my classes, how do I get the baseclass name of my current class using reflection.
Thanq in advance.
You can use Type.BaseType to get the base class type: http://msdn.microsoft.com/en-us/library/system.type.basetype.aspx
If you're trying to get the base class name, it'd be something like:
Type classType = typeof(YourClass); Type baseType = classType.BaseType; string baseClassName = baseType.Name;Note that, if you recursively search the base types, when you call BaseType on typeof(System.Object), you'll get null.
这篇关于如何使用反射从我的Assembly中使用派生类获取基类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!