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