Attribute List - Visual Basic (original) (raw)

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

Syntax

[ attributemodifier ] attributename [ ( attributearguments | attributeinitializer ) ]  

Parts

Part Description
attributemodifier Required for attributes applied at the beginning of a source file. Can be Assembly 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.

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.

For more information on when to use attributes, see Attributes overview. For information on attribute names, see Declared Element Names.

Rules

Example

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.

See also