ReadOnlyAttribute.IsReadOnly Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene un valore che indica se la proprietà a cui è associato questo attributo è di sola lettura.
public:
property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean
Valore della proprietà
true se la proprietà a cui è associato questo attributo è di sola lettura; false se la proprietà è di lettura/scrittura.
Esempio
Nell'esempio di codice seguente viene verificato se MyProperty è di sola lettura. Prima di tutto, il codice ottiene gli attributi per MyProperty eseguendo le operazioni seguenti:
Recupero di un PropertyDescriptorCollection oggetto con tutte le proprietà per l'oggetto .
Indicizzazione in PropertyDescriptorCollection per ottenere
MyProperty.Salvataggio degli attributi per questa proprietà nella variabile degli attributi.
Il codice imposta myAttribute quindi sul valore di ReadOnlyAttribute in AttributeCollection e controlla se la proprietà è di sola lettura.
// 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