Почему получение атрибутов работает по-разному при использовании PropertyDescriptor и PropertyInfo?

Я понимаю, что вызов GetCustomAttribute возвращает новый сгенерированный атрибут, но почему я не могу получить атрибут с помощью свойства Attribute?

Я приложил этот пример:

Определения:

    public class MyTestAttribute : Attribute
    {
       public int Test { get; set; }
    }

    public class TestClass
    {
       [MyTest]
       public int Property { get; set; }
    }

Код:

    // PropertyInfo
    var prop = typeof(TestClass).GetProperty("Property");
    var attr1 = prop.GetCustomAttribute(typeof(MyTestAttribute), false) as MyTestAttribute;
    attr1.Test = 12;

    var attr2 = prop.GetCustomAttribute(typeof(MyTestAttribute), false) as MyTestAttribute;
    // attr2.Test == 0 since GetCustomAttribute creates a new attribute.
    var attr3 = prop.Attributes; //attr3 = None

    // PropertyDescriptor
    var tProp = TypeDescriptor.GetProperties(typeof(TestClass)).Cast<PropertyDescriptor>().First(p => p.Name == "Property");
    var tAttr1 = tProp.Attributes.Cast<Attribute>().OfType<MyTestAttribute>().First();
    tAttr1.Test = 12;

    var tProp2 = TypeDescriptor.GetProperties(typeof(TestClass)).Cast<PropertyDescriptor>().First(p => p.Name == "Property");
    var tAttr2 = tProp2.Attributes.Cast<Attribute>().OfType<MyTestAttribute>().First(); 
    // tAttr2.Test == 12

person Amir Popovich    schedule 26.05.2015    source источник
comment
Я предполагаю, что вы читали... stackoverflow.com/questions/301356/?   -  person Paul Zahra    schedule 26.05.2015
comment
@PaulZahra - Спасибо. Я не был знаком с различиями. Я погуглю и почитаю о различиях.   -  person Amir Popovich    schedule 26.05.2015