从基类调用时,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
}
Run Code Online (Sandbox Code Playgroud)
或者我应该创建一个抽象方法,派生类必须实现如下所示?
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();
}
}
Run Code Online (Sandbox Code Playgroud)