I have the following (greatly simplified) classes:
public class Customer {
[Required(ErrorMessageResourceName="Required", ErrorMessageResourceType=typeof(ResourcesCommon.ValidationStrings))]
public string LastName { get; set; }
}
public class SalesCustomer : Customer {
...
}
I have some validation code that loops through SalesCustomer properties. Each property is evaluated with this:
var validators = property.GetCustomAttributes(typeof(ValidationAttribute), true);
The problem is that the Required attribute is not getting returned when I look at the LastName property on the SalesCustomer type but it does work fine when I look at the Customer type. This is confusing since the GetCustomerAttribute() method explicitly wants a boolean indicating that the inherited attributes will be returned.
I believe that it will only return attributes from overridden parent members, not shadowed parent members.
Make the base property
virtualand the child propertyoverrrides.