ReadOnlyAttribute.IsReadOnly Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recebe um valor que indica se a propriedade a que este atributo está ligado é apenas de leitura.
public:
property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean
Valor de Propriedade
true se a propriedade a que este atributo está ligado for apenas de leitura; false se a propriedade for leitura/escrita.
Exemplos
O seguinte exemplo de código verifica se MyProperty é só de leitura. Primeiro, o código obtém os atributos para MyProperty fazendo o seguinte:
Recuperar um PropertyDescriptorCollection com todas as propriedades do objeto.
Indexando em para PropertyDescriptorCollection obter
MyProperty.Guardar os atributos desta propriedade na variável de atributos.
Depois, o código define myAttribute o valor de no ReadOnlyAttributeAttributeCollection e verifica se a propriedade é apenas de leitura.
// 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