Attribute List (Visual Basic)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
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 ) ]
Required. Name of the attribute.
Optional. List of positional arguments for this attribute. Multiple arguments are separated by commas.
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.
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. If you supply an attribute list, you must enclose it in angle brackets ("
<" 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.
Modifiers. An attribute modifier (
Module) is required on every attribute applied to a programming element at the beginning of a source file. Attribute modifiers are not allowed on attributes applied to elements that are not at the beginning of a source file.
Arguments. All positional arguments for an attribute must precede any variable or property initializers.
The following example applies the DllImportAttribute attribute to a skeleton definition of a
<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.