ReadOnlyAttribute.IsReadOnly Vlastnost

Definice

Získá hodnotu určující, zda vlastnost, ke které 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 je vlastnost, ke které je tento atribut vázán, je jen pro čtení; false pokud je vlastnost pro čtení a zápis.

Příklady

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

Kód se pak nastaví myAttribute na hodnotu ReadOnlyAttribute v objektu AttributeCollection a zkontroluje, zda je vlastnost určena 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é