Home All Groups Group Topic Archive Search About

GetCustomAttributes(true) not working when on an overriden Propert

Author
6 Jun 2006 5:28 PM
Patrick
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

Author
6 Jun 2006 6:36 PM
Patrick
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...

Show quote
"Patrick" wrote:

> 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
>

AddThis Social Bookmark Button