使用Reflection获取父类的名称

And*_*hin 41 .net reflection

如何使用Reflection获取某些类的父类的名称?

Max*_*erl 57

像这样:

typeof(Typ).BaseType.Name
Run Code Online (Sandbox Code Playgroud)


Cra*_*ste 23

我来到这个问题寻找一个声明一个嵌套类的类,它是DeclaringType.

this.GetType().DeclaringType.Name
Run Code Online (Sandbox Code Playgroud)

也许不是OP提出的要求,但也许其他人来这里的搜索标准和我一样.;-)


Raz*_*zie 7

您可以使用:

string baseclassName = typeof(MyClass).BaseType.Name;
Run Code Online (Sandbox Code Playgroud)


JDu*_*ley 5

        Type type = obj.GetType();
        Type baseType = type.BaseType;
        string baseName = baseType.Name;
Run Code Online (Sandbox Code Playgroud)


小智 5

上面的问题是询问父类型,可以使用以下方法检索:

yourRefVar.GetType().UnderlyingSystemType.Name