ReadOnlyAttribute.IsReadOnly Properti

Definisi

Mendapatkan nilai yang menunjukkan apakah properti yang terikat atribut ini bersifat baca-saja.

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

Nilai Properti

true jika properti yang terikat dengan atribut ini bersifat baca-saja; false jika properti adalah baca/tulis.

Contoh

Contoh kode berikut memeriksa untuk melihat apakah MyProperty bersifat baca-saja. Pertama, kode mendapatkan atribut untuk MyProperty dengan melakukan hal berikut:

Kemudian kode diatur myAttribute ke nilai ReadOnlyAttribute di AttributeCollection dan memeriksa apakah properti bersifat baca-saja.

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

Berlaku untuk

Lihat juga