ReadOnlyAttribute.IsReadOnly Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Beolvas egy értéket, amely jelzi, hogy az attribútumhoz kötött tulajdonság írásvédett-e.
public:
property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean
Tulajdonság értéke
true ha az attribútumhoz kötött tulajdonság írásvédett; false ha a tulajdonság írási/olvasási.
Példák
Az alábbi példakód ellenőrzi, hogy írásvédett-e MyProperty . Először is a kód az alábbi műveletekkel szerzi be az attribútumokat MyProperty :
PropertyDescriptorCollection Az objektum összes tulajdonságát tartalmazó lekérdezés.
Indexelés a PropertyDescriptorCollection lekéréshez
MyProperty.A tulajdonság attribútumainak mentése az attribútum változóban.
Ezután a kód a benne lévő myAttribute értékre ReadOnlyAttribute állítjaAttributeCollection, és ellenőrzi, hogy a tulajdonság írásvédett-e.
// 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