ReadOnlyAttribute.IsReadOnly Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob die Eigenschaft, an die dieses Attribut gebunden ist, schreibgeschützt ist.

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

Eigenschaftswert

true wenn die Eigenschaft, an die dieses Attribut gebunden ist, schreibgeschützt ist; false wenn die Eigenschaft lese-/schreibgeschützt ist.

Beispiele

Im folgenden Codebeispiel wird überprüft, ob MyProperty schreibgeschützt ist. Zunächst ruft der Code die Attribute für MyProperty folgendes ab:

Anschließend wird der Code auf den Wert des Ins myAttributeReadOnlyAttribute festgelegt AttributeCollection und überprüft, ob die Eigenschaft schreibgeschützt ist.

// 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

Gilt für:

Weitere Informationen