如何在运行时获取当前类名? [英] How to get the current class name at runtime?
本文介绍了如何在运行时获取当前类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将当前类名放入字符串中.
I'm trying to get a current class name into a string.
例如:
public class Marker : Mark
{
string currentclass = ???;
}
public abstract class MiniMarker : Mark
{
}
我想从 Marker
类中获取字符串,这样我就不必把它放在我用它制作的每个抽象类中.
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.
我希望字符串是 MiniMarker
,或者抽象类的名字.
I want the string to be MiniMarker
, or what ever the abstract class is named.
我尝试了 MethodBase.GetCurrentMethod().DeclaringType
,但没有奏效.
I tried MethodBase.GetCurrentMethod().DeclaringType
, but it did not work.
推荐答案
this.GetType().Name
应该返回一个类名
这篇关于如何在运行时获取当前类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文