Export (0) Print
Expand All

Attributes Used in Visual Basic .NET

The following table lists some of the more common attributes used in Visual Basic .NET. For information about a specific attribute, type the attribute name in the Index or Search field 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 .NET.
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 .NET.
VBFixedArrayAttribute Class Specifies the size of a fixed array in a structure for use with file input and output functions. Specific to Visual Basic .NET.
WebMethodAttribute Class Makes a method callable using the SOAP protocol. Used in XML Web services.
SerializableAttribute Class Indicates that a class can be serialized.
MarshalAsAttribute Class Determines how a parameter should be marshaled between the managed code of Visual Basic .NET and unmanaged code such as a Windows API. Used by the common language runtime.
AttributeUsageAttribute Class Specifies how an attribute can be used.
DllImportAttribute Class Indicates that the attributed method is implemented as an export from an unmanaged DLL.

Attributes Specific to Visual Basic .NET

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

COMClassAttribute

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

VBFixedStringAttribute

Use VBFixedStringAttribute to force Visual Basic .NET to create a fixed-string array. Arrays 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 .NET strings, arrays are of variable length by default. This attribute is useful when serializing or writing data to files.

See Also

Global Attributes | Extending Metadata Using Attributes | Applying Attributes | Retrieving Attribute Information | Retrieving Information Stored in Attributes | Writing Custom Attributes | COMClassAttribute Class | VBFixedArrayAttribute Class | VBFixedStringAttribute Class | System.Runtime.InteropServices Namespace | WebMethodAttribute Class | SerializableAttribute Class | MarshalAsAttribute Class | AttributeUsageAttribute Class | DllImportAttribute Class

Show:
© 2014 Microsoft