ReadOnlyAttribute.IsReadOnly Właściwość

Definicja

Pobiera wartość wskazującą, czy właściwość, z którymi jest powiązany ten atrybut, jest tylko do odczytu.

public:
 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean

Wartość właściwości

true jeśli właściwość ta atrybut jest powiązana z jest tylko do odczytu; false jeśli właściwość jest odczyt/zapis.

Przykłady

Poniższy przykład kodu sprawdza, czy MyProperty jest tylko do odczytu. Najpierw kod pobiera atrybuty, MyProperty wykonując następujące czynności:

Następnie kod ustawia myAttribute wartość ReadOnlyAttribute elementu w AttributeCollection obiekcie i sprawdza, czy właściwość jest tylko do odczytu.

// 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.
}
// Gets the attributes for the property.
AttributeCollection attributes = 
   TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

// Checks to see whether the property is read-only.
ReadOnlyAttribute myAttribute = 
   (ReadOnlyAttribute)attributes[typeof(ReadOnlyAttribute)];

if(myAttribute.IsReadOnly) {
   // Insert code here.
}
' Gets the attributes for the property.
Dim attributes As AttributeCollection = _
   TypeDescriptor.GetProperties(Me)("MyProperty").Attributes
       
' Checks to see whether the property is read-only.
Dim myAttribute As ReadOnlyAttribute = _
   CType(attributes(GetType(ReadOnlyAttribute)), ReadOnlyAttribute)
   
If myAttribute.IsReadOnly Then
    ' Insert code here.
End If

Dotyczy

Zobacz też