Partilhar via


WriteOnly (Visual Basic)

Specifies that a property can be written but not read.

Comentários

Rules

Declaration Context. Você pode usar WriteOnly somente no nível de módulo . This means the declaration context for a WriteOnly property must be a class, structure, or module, and cannot be a source file, namespace, or procedure.

You can declare a property as WriteOnly, but not a variable.

When to Use WriteOnly

Sometimes you want the consuming code to be able to set a value but not discover what it is. For example, sensitive data, such as a social registration number or a password, needs to be protected from access by any component that did not set it. In these cases, you can use a WriteOnly property to set the value.

Observação de segurançaObservação sobre segurança

When you define and use a WriteOnly property, consider the following additional protective measures:

  • Substituindo. Se a propriedade for um membro de uma classe, permitir que ele seja o padrão NotOverridable (Visual Basic)e não o declara Overridable ou MustOverride. This prevents a derived class from making undesired access through an override.

  • Nível de acesso. Se você mantiver os dados confidenciais da propriedadeem uma ou mais variáveis, declará-los Private (Visual Basic) para que nenhum outro código possa acessá-los.

  • Encryption. Store all sensitive data in encrypted form rather than in plain text. If malicious code somehow gains access to that area of memory, it is more difficult to make use of the data. Encryption is also useful if it is necessary to serialize the sensitive data.

  • Resetting. When the class, structure, or module defining the property is being terminated, reset the sensitive data to default values or to other meaningless values. This gives extra protection when that area of memory is freed for general access.

  • Persistence. Do not persist any sensitive data, for example on disk, if you can avoid it. Also, do not write any sensitive data to the Clipboard.

The WriteOnly modifier can be used in this context:

Propriedade declaração

Consulte também

Referência

ReadOnly (Visual Basic)

Private (Visual Basic)

Outros recursos

Palavras-chave (Visual Basic)