This seems to work fine for me if you just use the .GetType () method. GetCustomAttributes (true) this does not return any attributes, even if you set Inherited = true.
[AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = true)] sealed class MyAttribute : Attribute { public MyAttribute() { } } [AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = true)] sealed class MyAttribute1 : Attribute { public MyAttribute1() { } } class Class1 { [MyAttribute()] public virtual string test { get; set; } } class Class2 : Class1 { [MyAttribute1()] public override string test { get { return base.test; } set { base.test = value; } } }
Then get custom attributes from class 2.
Class2 a = new Class2(); MemberInfo memberInfo = typeof(Class2).GetMember("test")[0]; object[] attributes = Attribute.GetCustomAttributes(memberInfo, true);
attributes show 2 elements in an array.
source share