Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReadOnlyAttribute vs PropertyDescriptor.IsReadOnly()

What is the difference between using a PropertyDescriptor that returns a value for the IsReadOnly() method, and one that is associated with a ReadOnlyAttribute?

like image 740
Eric Anastas Avatar asked Apr 16 '09 17:04

Eric Anastas


2 Answers

The main difference is that this allows you to seize more control if you provide your own PropertyDescriptor implementation (via ICustomTypeDescriptor, TypeDescriptionProvider or TypeConverter). Then you can choose your own logic for when it is writeable - for example, based on access rights.

But yes; under the default implementation, it will report read-only for properties without setters, and for properties marked with ReadOnlyAttribute.

like image 177
Marc Gravell Avatar answered Nov 15 '22 10:11

Marc Gravell


No difference when I look at it using Reflector.

One of the derived class SimplePropertyDescriptor has the following code.


    public override bool IsReadOnly
    {
        get
        {
            return this.Attributes.Contains(ReadOnlyAttribute.Yes);
        }
    }

like image 25
shahkalpesh Avatar answered Nov 15 '22 11:11

shahkalpesh