Home > Articles

  • Print
  • + Share This

Marking Classes As Visual Basic Modules

Type library modules with constants are imported as plain classes, but if you mark them with a certain custom attribute—Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute—the Visual Basic .NET compiler treats them as modules. This means that their members can be referred to globally rather than qualified with their class name. To add this custom attribute, change a class like the following

.class public abstract auto ansi MyModule
     extends [mscorlib]System.Object
{
 ...
}

to

.class public abstract auto ansi MyModule
     extends [mscorlib]System.Object
{
 .custom instance void [Microsoft.VisualBasic]
  Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute::.ctor()
  = ( 01 00 00 00 )
 ...
}

In addition, you must add a reference to the Microsoft.VisualBasic assembly, which defines the custom attribute, in the same location as the other .assembly extern blocks:

.assembly extern Microsoft.VisualBasic
{
 .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )
 .ver 7:0:3300:0
}

The .publickeytoken, and .ver values must correspond to the desired version of the Microsoft.VisualBasic assembly.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.