Search code examples
c#reflectionsystem.reflection

Using the PropertyDescriptor can I determine if a property is overridden in the current class


If I have:

class A
{
    public virtual string Owner { get; set; }
}

class B : A
{
    public override string Owner { get; set; }
}

How do I determine that owner property on class B is an override property using the TypeDescriptor.GetProperties(type) method?


Solution

  • Based on @DaveShaw's comment and the answers for similar questions using propertyInfo :

    var property = TypeDescriptor.GetProperties(typeof(B)).Find("Owner", false).ComponentType.GetProperty("Owner");
    var getMethod = property.GetGetMethod(false);
    bool isOverride = getMethod.GetBaseDefinition() != getMethod;