سؤال

What's the purpose of the Readonly attribute on properties? Metadata for use elsewhere?

هل كانت مفيدة؟

المحلول

It is used in a few places; PropertyGrid for example will respect this attribute, allowing it to be read-write in code, but read-only in the UI (strictly speaking, it is the PropertyDescriptor that does this - PropertyGrid obeys the descriptor; the same effect can be achieved by using custom descriptors). Some serializers may also respect it. It isn't used much, to be honest. If you think that one is obscure - [ImmutableObjectAttribute] is used even less; as far as I know, the IDE uses it to decide whether to show attribute properties, when editing attributes. That's about it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top