[英]Using the PropertyDescriptor can I determine if a property is overridden in the current class
如果我有:
class A
{
public virtual string Owner { get; set; }
}
class B : A
{
public override string Owner { get; set; }
}
如何使用TypeDescriptor.GetProperties(type)
方法確定B
類上的owner屬性是覆蓋屬性?
根據@ DaveShaw的評論和使用propertyInfo的類似問題的答案:
var property = TypeDescriptor.GetProperties(typeof(B)).Find("Owner", false).ComponentType.GetProperty("Owner");
var getMethod = property.GetGetMethod(false);
bool isOverride = getMethod.GetBaseDefinition() != getMethod;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.