从基类调用时,GetType()是否会返回派生最多的类型?
例:
public abstract class A
{
private Type GetInfo()
{
return System.Attribute.GetCustomAttributes(this.GetType());
}
}
public class B : A
{
//Fields here have some custom attributes added to them
}
还是我应该使派生类必须实现的抽象方法如下所示?
public abstract class A
{
protected abstract Type GetSubType();
private Type GetInfo()
{
return System.Attribute.GetCustomAttributes(GetSubType());
}
}
public class B : A
{
//Fields here have some custom attributes added to them
protected Type GetSubType()
{
return GetType();
}
}
10
好-您是否尝试过?
—
BrokenGlass 2011年
@BrokenGlass通常我会那样做,但是我不在电脑旁……只是用我的手机发帖,因为问题的解决方案开始形成,我很好奇现在知道!= P
—
Feisty Mango