GetCustomAttributesのinheritについて

GetCustomAttributesのinheritの意味がすごく分かりにくいので調べてみた

class XAttribute : Attribute { }

class Unko
{
  [X]
  public virtual void Method() { }
}

class Manko : Unko
{
  public override void Method() { }
}

var method = typeof(Manko).GetMethod("Method");
var attr = (XAttribute)method.GetCustomAttributes(typeof(XAttribute), true)[0];

これがとってこれるのがinherit=trueの力だ。継承してoverrideしたものは、属性も付け直さなきゃいけないんだが、inheritをtrueにすると継承前の属性も探してきてくれる。inheritがfalseだろうとtrueだろうと、

DerivedAttribute : BaseAttribute

継承した属性は基底クラスの属性をtypeofで指定すればとってこれる。勘違いしやすい。