What is the difference between using a PropertyDescriptor that returns a value for the IsReadOnly() method, and one that is associated with a ReadOnlyAttribute?
+3
A:
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);
}
}
shahkalpesh
2009-04-16 18:09:10
+1
A:
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
.
Marc Gravell
2009-04-16 19:48:47
So say I am creating my own PropertyDescriptor via ICustomTypeDescriptor then the IsReadOnly() method will override whatever ReadOnly attributes have already been applied to it?
Eric Anastas
2009-04-16 22:31:20
That is correct.
Marc Gravell
2009-04-17 07:25:32