如何在运行时获取当前类名? [英] How to get the current class name at runtime?

查看:178
本文介绍了如何在运行时获取当前类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将当前类名作为字符串。



例如:

  public class Marker:Mark 
{
string currentclass = ???
}

public abstract class MiniMarker:Mark
{
}

我想从 Marker 类中获取字符串,所以我不必将它放在每个抽象类中。 / p>

我想要的字符串 MiniMarker ,或者什么抽象类命名。



我试过 MethodBase.GetCurrentMethod()。DeclaringType ,但它没有工作。

解决方案

  this.GetType()。Name 

应返回类名


I'm trying to get a current class name into a string.

For example:

public class Marker : Mark
{
    string currentclass = ???;
}

public abstract class MiniMarker : Mark
{
}

I'd like to get the string from Marker class so I do not have to put it inside each abstract class I make from it.

I want the string to be MiniMarker, or what ever the abstract class is named.

I tried MethodBase.GetCurrentMethod().DeclaringType, but it did not work.

解决方案

   this.GetType().Name

should return a Class name

这篇关于如何在运行时获取当前类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆