インターフェイスで宣言されているプロパティの属性を使用しようとしました。インターフェイスからの継承プロパティの属性の使用
仮定します
今[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; }
}
を、私が読んだものから、GetCustomAttributeを()継承=真では、継承された属性を返す必要がありますが、それはそれは動作しません見えます。
Attribute my = typeof(Child).GetProperty("y").GetCustomAttribute(typeof(My1Attribute), true); // my == null
なぜ機能しないのですか?どのように属性を取得できますか?