從基類調用時,GetType()是否返回派生類型最多?從基類中調用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();
}
}
好 - 你試過嗎? – BrokenGlass 2011-04-25 16:40:58
@BrokenGlass通常我會這樣做,但我不在電腦......只是用我的手機來發帖,因爲問題的解決方案已經開始形成,我很想知道現在! = P – 2011-04-25 16:43:11