ReadOnlyAttribute::IsReadOnly Property
.NET Framework (current version)
Gets a value indicating whether the property this attribute is bound to is read-only.
Assembly: System (in System.dll)
Property Value
Type: System::Booleantrue if the property this attribute is bound to is read-only; false if the property is read/write.
The following code example checks to see whether MyProperty is read-only. First, the code gets the attributes for MyProperty by doing the following:
Retrieving a PropertyDescriptorCollection with all the properties for the object.
Indexing into the PropertyDescriptorCollection to get MyProperty.
Saving the attributes for this property in the attributes variable.
Then the code sets myAttribute to the value of the ReadOnlyAttribute in the AttributeCollection and checks whether the property is read-only.
// Gets the attributes for the property. AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyProperty" ]->Attributes; // Checks to see whether the property is read-only. ReadOnlyAttribute^ myAttribute = dynamic_cast<ReadOnlyAttribute^>(attributes[ ReadOnlyAttribute::typeid ]); if ( myAttribute->IsReadOnly ) { // Insert code here. }
.NET Framework
Available since 1.1
Silverlight
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Available since 1.1
Silverlight
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Show: