ReadOnlyAttribute.IsReadOnly Tulajdonság

Definíció

Beolvas egy értéket, amely jelzi, hogy az attribútumhoz kötött tulajdonság írásvédett-e.

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

Tulajdonság értéke

true ha az attribútumhoz kötött tulajdonság írásvédett; false ha a tulajdonság írási/olvasási.

Példák

Az alábbi példakód ellenőrzi, hogy írásvédett-e MyProperty . Először is a kód az alábbi műveletekkel szerzi be az attribútumokat MyProperty :

Ezután a kód a benne lévő myAttribute értékre ReadOnlyAttribute állítjaAttributeCollection, és ellenőrzi, hogy a tulajdonság írásvédett-e.

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

A következőre érvényes:

Lásd még