I've been trying to use an attribute of a property that has been declared in an interface.
Assume:
[AttributeUsage(AttributeTargets.Property, Inherited=true)]
class My1Attribute : Attribute
{
public int x { get; set; }
}
interface ITest
{
[My1]
int y { get; set; }
}
class Child : ITest
{
public Child() { }
public int y { get; set; }
}
Now, from what I read, GetCustomAttribute() with inheritance=true should return the inherited attribute, but it looks it doesn't work.
Attribute my = typeof(Child).GetProperty("y").GetCustomAttribute(typeof(My1Attribute), true); // my == null
Why doesn't it work? and how can I get the attribute?