GetCustomAttributes(true) not working when on an overriden Propert

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I just found out that if i have this code

public class A
{
[MyAttribute()]
public virtual int MyInt { get { return 1; } }
}

public class SubA : A
{
public override int MyInt { get { return 2; } }
}

calling GetCustomAttributes(true) on the SubA.MyInt propertyInfo doesnt
return the MyAttribute object...and that shouldnt be the case!!! I really is
a problem...do you guys have an explenation ...Am I doing something wrong???

Thanks
 
Ok found out on a blog that for PropertyInfo the method doesnt work as
documented... you need to use Attribute.GetCustomAttributes(propertyInfo,
true) to get inherited custom attributes...
 
Back
Top