ReadOnlyAttribute.IsReadOnly Vlastnost

Definice

Získá hodnotu označující, zda vlastnost, na kterou je tento atribut vázán, je jen pro čtení.

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

Hodnota vlastnosti

true pokud vlastnost, na který je tento atribut vázán, je jen pro čtení; false pokud je vlastnost pro čtení/zápis.

Příklady

Následující příklad kódu zkontroluje, jestli MyProperty je jen pro čtení. Nejprve kód získá atributy pro MyProperty následujícím způsobem:

Pak kód nastaví myAttribute hodnotu ReadOnlyAttribute v objektu AttributeCollection a zkontroluje, jestli je vlastnost jen pro čtení.

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

Platí pro

Viz také