ReadOnlyAttribute(Boolean) Construtor

Definição

Inicializa uma nova instância da classe ReadOnlyAttribute.Initializes a new instance of the ReadOnlyAttribute class.

public:
 ReadOnlyAttribute(bool isReadOnly);
public ReadOnlyAttribute (bool isReadOnly);
new System.ComponentModel.ReadOnlyAttribute : bool -> System.ComponentModel.ReadOnlyAttribute
Public Sub New (isReadOnly As Boolean)

Parâmetros

isReadOnly
Boolean

true para mostrar que a propriedade à qual esse atributo é associado é somente leitura; false para mostrar que a propriedade é leitura/gravação.true to show that the property this attribute is bound to is read-only; false to show that the property is read/write.

Exemplos

O exemplo de código a seguir marca uma propriedade como somente leitura.The following code example marks a property as read-only. Esse código cria um novo ReadOnlyAttribute , define seu valor como ReadOnlyAttribute.Yes e o associa à propriedade.This code creates a new ReadOnlyAttribute, sets its value to ReadOnlyAttribute.Yes, and binds it to the property.

public:
   [ReadOnly(true)]
   property int MyProperty 
   {
      int get()
      {
         // Insert code here.
         return 0;
      }
      void set( int value )
      {
         // Insert code here.
      }
   }
[ReadOnly(true)]
public int MyProperty {
   get {
      // Insert code here.
      return 0;
   }
   set {
      // Insert code here.
   }
}
   
<ReadOnlyAttribute(True)> _
Public Property MyProperty() As Integer
    Get
        ' Insert code here.
        Return 0
    End Get
    Set
        ' Insert code here.
    End Set
End Property

Comentários

Os membros que estão marcados com o ReadOnlyAttribute conjunto para true ou que não têm um Set método não podem ser alterados.Members that are marked with the ReadOnlyAttribute set to true or that do not have a Set method cannot be changed. Os membros que não têm esse atributo ou que estão marcados com o ReadOnlyAttribute conjunto como false são de leitura/gravação e podem ser alterados.Members that do not have this attribute or that are marked with the ReadOnlyAttribute set to false are read/write, and they can be changed. O padrão é No.The default is No.

Observação

Quando você marca uma propriedade com o ReadOnlyAttribute conjunto como true , o valor desse atributo é definido como o membro constante Yes .When you mark a property with the ReadOnlyAttribute set to true, the value of this attribute is set to the constant member Yes. Para uma propriedade marcada com o ReadOnlyAttribute definido como false , o valor é No .For a property marked with the ReadOnlyAttribute set to false, the value is No. Portanto, quando você quiser verificar o valor desse atributo em seu código, deverá especificar o atributo como ReadOnlyAttribute.Yes ou ReadOnlyAttribute.No .Therefore, when you want to check the value of this attribute in your code, you must specify the attribute as ReadOnlyAttribute.Yes or ReadOnlyAttribute.No.

Aplica-se a

Confira também