ReadOnlyAttribute.IsReadOnly Eigenschap

Definitie

Hiermee wordt een waarde opgehaald die aangeeft of de eigenschap waaraan dit kenmerk is gebonden, alleen-lezen is.

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

Waarde van eigenschap

true als de eigenschap waaraan dit kenmerk is gebonden, alleen-lezen is; false als de eigenschap lezen/schrijven is.

Voorbeelden

In het volgende codevoorbeeld wordt gecontroleerd of MyProperty het kenmerk Alleen-lezen is. Eerst haalt de code de kenmerken op MyProperty waarvoor u het volgende doet:

Vervolgens wordt de code ingesteld myAttribute op de waarde van de ReadOnlyAttribute in de AttributeCollection code en wordt gecontroleerd of de eigenschap het kenmerk Alleen-lezen heeft.

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

Van toepassing op

Zie ook