using System;
class Program
{
static void Main()
{
var p = typeof(MyClass2).GetProperty("Value");
var a = Attribute.GetCustomAttribute(p, typeof(ObsoleteAttribute), true);
Console.WriteLine(a != null);
}
}
public class MyClass
{
[CommandProperty()]
public virtual string Value { get; set; }
}
public class MyClass2 : MyClass
{
public override string Value { get; set; }
}
[AttributeUsage( AttributeTargets.Property, Inherited = true)]
public class CommandPropertyAttribute : Attribute
{
/* ... */
}
PropertyInfo prop = ***The PropertyInfo of MyClass2.Value***;
object[] attrs = prop.GetCustomAttributes( typeofCPA, true );
Attribute at =Attribute.GetCustomAttribute(prop, typeofCPA, true);
if (attrs.Length == 0 && at != null)
{
// Yes this happens.
}
Почему я не получаю результат при первом вызове GetCustomAttributes?