ReadOnlyAttribute.IsReadOnly Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
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:
Ruft eine PropertyDescriptorCollection mit allen Eigenschaften für das Objekt ab.
Indizieren in der PropertyDescriptorCollection abzurufenden
MyPropertyDatei .Speichern der Attribute für diese Eigenschaft in der Attributvariable.
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