[英]Get the name of class inheriting from base class in C#
I have the following base class 我有以下基础课
class BaseClass
{
//Want to get the name of class A only, even if B is inherited from A
}
class A : BaseClass
{
}
class B : A
{
}
Can someone help me with getting the name of class A only from the base class. 有人可以帮我仅从基类中获取类A的名称。
Thanks 谢谢
public abstract class BaseClass
{
public void GetInheritorName()
{
var nameIs = this.InheritorTellMeYourName();
}
protected abstract string InheritorTellMeYourName();
}
public class A : BaseClass
{
protected sealed override string InheritorTellMeYourName()
{
return typeof(A).Name;
}
}
public class B : A
{
}
Like someone mentioned in the comments, you shouldn't usually need anything like that... 就像评论中提到的人一样,您通常不需要这样的东西...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.