ReadOnlyAttribute.IsReadOnly Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient une valeur indiquant si la propriété à laquelle cet attribut est lié est en lecture seule.
public:
property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean
Valeur de propriété
true si la propriété à laquelle cet attribut est lié est en lecture seule ; false si la propriété est en lecture/écriture.
Exemples
L’exemple de code suivant vérifie s’il MyProperty s’agit d’une lecture seule. Tout d’abord, le code obtient les attributs pour MyProperty tableaux suivants :
Récupération d’une PropertyDescriptorCollection propriété avec toutes les propriétés de l’objet.
Indexation dans l’index PropertyDescriptorCollection pour obtenir
MyProperty.Enregistrement des attributs pour cette propriété dans la variable d’attributs.
Ensuite, le code définit myAttribute la valeur de l’élément ReadOnlyAttribute dans le AttributeCollection code et vérifie si la propriété est en lecture seule.
// 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