Partilhar via


Lista de atributos (Visual Basic)

Specifies the attributes to be applied to a declared programming element. Multiple attributes are separated by commas. Following is the syntax for one attribute.

[ attributemodifier ] attributename [ ( attributearguments | attributeinitializer ) ]

Parts

  • attributemodifier
    Required for attributes applied at the beginning of a source file. Can be Assembly (Visual Basic) or Module.

  • attributename
    Required. Name of the attribute.

  • attributearguments
    Optional. List of positional arguments for this attribute. Multiple arguments are separated by commas.

  • attributeinitializer
    Optional. List of variable or property initializers for this attribute. Multiple initializers are separated by commas.

Comentários

You can apply one or more attributes to nearly any programming element (types, procedures, properties, and so forth). Attributes appear in your assembly's metadata, and they can help you annotate your code or specify how to use a particular programming element. You can apply attributes defined by Visual Basic and the .NET Framework, and you can define your own attributes.

Para obter mais informações sobre quando usar os atributos, consulte Atributos (C# e Visual Basic). For information on attribute names, see Nomes de elementos declarados (Visual Basic).

Rules

  • Placement. You can apply attributes to most declared programming elements. To apply one or more attributes, you place an attribute block at the beginning of the element declaration. Each entry in the attribute list specifies an attribute you wish to apply, and the modifier and arguments you are using for this invocation of the attribute.

  • Angle Brackets. Se você fornecer uma lista de atributo , deve colocar colchetes angulares ("<" and ">").

  • Part of the Declaration. The attribute must be part of the element declaration, not a separate statement. You can use the line-continuation sequence (" _") to extend the declaration statement onto multiple source-code lines.

  • Modificadores. O modificador de atributo (Assembly ou Module) é necessário em cada atributo aplicado a um elemento de programação no início de um arquivo de fonte . Attribute modifiers are not allowed on attributes applied to elements that are not at the beginning of a source file.

  • Argumentos. All positional arguments for an attribute must precede any variable or property initializers.

Exemplo

The following example applies the DllImportAttribute attribute to a skeleton definition of a Function procedure.

<DllImportAttribute("kernel32.dll", EntryPoint:="MoveFileW", 
    SetLastError:=True, CharSet:=CharSet.Unicode, 
    ExactSpelling:=True, 
    CallingConvention:=CallingConvention.StdCall)> 
Public Shared Function moveFile(ByVal src As String, 
  ByVal dst As String) As Boolean
    ' This function copies a file from the path src to the path dst.
    ' Leave this function empty. The DLLImport attribute forces calls
    ' to moveFile to be forwarded to MoveFileW in KERNEL32.DLL.
End Function

DllImportAttribute indicates that the attributed procedure represents an entry point in an unmanaged dynamic-link library (DLL). The attribute supplies the DLL name as a positional argument and the other information as variable initializers.

Consulte também

Tarefas

Como: Quebrar e combinar instruções no código (Visual Basic)

Referência

Assembly (Visual Basic)

Módulo <keyword> (Visual Basic)

Atributos (C# e Visual Basic)