Specifies the attributes to be applied to a declared programming element. Multiple attributes are separated by commas. Following is the syntax for one attribute.
Required for attributes applied at the beginning of a source file. Can be Module.or
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.
For more information on when to use attributes, seeand . For information on attribute names, see .
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 (Assembly or 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 theattribute 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.