ReadOnlyAttribute.IsReadOnly Özellik

Tanım

Bu özniteliğin bağlı olduğu özelliğin salt okunur olup olmadığını belirten bir değer alır.

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

Özellik Değeri

true bu özniteliğin bağlı olduğu özellik salt okunur ise; false özelliği okuma/yazma ise.

Örnekler

Aşağıdaki kod örneği salt okunur olup olmadığını MyProperty denetler. İlk olarak kod, aşağıdakileri yaparak özniteliklerini MyProperty alır:

Ardından kod içindeki AttributeCollection değerine ReadOnlyAttribute ayarlanır myAttribute ve özelliğin salt okunur olup olmadığını denetler.

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

Şunlara uygulanır

Ayrıca bkz.