GetCustomAttributes(true) not working when on an overriden Propert

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
 
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top