如果我有:
class A
{
public virtual string Owner { get; set; }
}
class B : A
{
public override string Owner { get; set; }
}
如何使用 TypeDescriptor.GetProperties(type)
方法确定类 B
上的所有者属性是覆盖属性?
最佳答案
基于@DaveShaw 的评论和使用 propertyInfo 对类似问题的回答:
var property = TypeDescriptor.GetProperties(typeof(B)).Find("Owner", false).ComponentType.GetProperty("Owner");
var getMethod = property.GetGetMethod(false);
bool isOverride = getMethod.GetBaseDefinition() != getMethod;
关于c# - 使用 PropertyDescriptor 可以确定属性是否在当前类中被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25415719/