Attributes Used in Visual BasicĀ 

The following table lists some of the more common attributes used in Visual Basic. For information about a specific attribute, type the attribute name in the Index or Search box of the Help system.

Attribute Purpose

ComClassAttribute Class

Indicates to the compiler that the class should be exposed as a COM object. Specific to Visual Basic.

HideModuleNameAttribute Class

Allows module members to be accessed using only the qualification needed for the module.

VBFixedStringAttribute Class

Specifies the size of a fixed-length string in a structure for use with file input and output functions. Specific to Visual Basic.

VBFixedArrayAttribute Class

Specifies the size of a fixed array in a structure for use with file input and output functions. Specific to Visual Basic.

WebMethodAttribute

Makes a method callable using the SOAP protocol. Used in XML Web services.

SerializableAttribute

Indicates that a class can be serialized.

MarshalAsAttribute

Determines how a parameter should be marshaled between the managed code ofVisual Basic and unmanaged code such as a Windows API. Used by the common language runtime.

AttributeUsageAttribute

Specifies how an attribute can be used.

DllImportAttribute

Indicates that the attributed method is implemented as an export from an unmanaged DLL.

Attributes Specific to Visual Basic

Three attributes are specific to Visual Basic: COMClassAttribute, VBFixedStringAttribute, and VBFixedArray.

COMClassAttribute

Use COMClassAttribute to simplify the process of creating COM components from Visual Basic. COM objects are considerably different from .NET Framework assemblies, and without COMClassAttribute, you need to follow a number of steps to generate a COM object from Visual Basic. For classes marked with COMClassAttribute, the compiler performs many of these steps automatically.

HideModuleNameAttribute

Use HideModuleNameAttribute to allows module members to be accessed using only the qualification needed for the module.

VBFixedStringAttribute

Use VBFixedStringAttribute to force Visual Basic to create a fixed-length string. Strings are of variable length by default, and this attribute is useful when storing strings to files. The following code demonstrates this:

Structure Worker
    ' The runtime uses VBFixedString to determine 
    ' if the field should be written out as a fixed size.
    <VBFixedString(10)> Public LastName As String
    <VBFixedString(7)> Public Title As String
    <VBFixedString(2)> Public Rank As String
End Structure

VBFixedArrayAttribute

Use VBFixedArrayAttribute to declare arrays that are fixed in size. Like Visual Basic strings, arrays are of variable length by default. This attribute is useful when serializing or writing data to files.

See Also

Reference

ComClassAttribute Class
VBFixedArrayAttribute Class
VBFixedStringAttribute Class
System.Runtime.InteropServices

Concepts

Global Attributes in Visual Basic
Applying Attributes
Retrieving Information Stored in Attributes
Writing Custom Attributes

Other Resources

Extending Metadata Using Attributes