The My Classes

Visual Basic.NET creates an implicit My class (and related classes) with helper APIs for common application programming tasks. Mercury provides the same classes, but they ar injected into the build in slightly different ways and it uses slightly diferent mechanics to determine what type of classes to create.

The My types are very specific to .NET, and not available on the other platforms.

How the My Classes are Generated

in Mercury, the My classes are not injected by the compiler, but are defined in a regular sorce code file that is generated by the build phase prior to core compilation, and passed to the compiler along with your own source files. If you look at the more detailed version of the build log, you will see this file in the list, it kis called My.pas (and for legacy reasons, its content is defined using the Oxygene language, not Mercury).

The file will be generated if the following four conditions are met:

  • The VBGenerateMy setting is set to True (the default)
  • The project has a RootNamespace set
  • The project platform is .NET
  • The project has a reference to "Microsoft.VisualBasic.dll" and/or "Mercury.dll"

The VBGenerateMy setting default to True, but you can explicitly set it to False if you want to forego the creation of a My classes.

The My Classes and Code Completion

Because the My.pas is created on build, it's contents will not be available to code completion and other IDE intelligence, until the first time you compile your project successfully.

Once your project has built, the classes become available to Code Completion and the Editor Code Model. Because they are diven by a plain source file, you can even use "Go to Definition" to open the generated file and review it.

In Fire and Water, the file (among potentially others) is also available via the "Other Files" item in the Jump Bar at the top of the editor.

Generated Classes

Visual Basic.NET uses the MyType project setting, also available to code via the _MYTYPE Conditional Define to determine what content to generate for the My classes. Mercury does not use thus setting (although project conversion does migrate it to a plain conditional define). Instead it relies on Elements more advanced conditional compilation to generate all possibly items in the My.pas file, but compile only those that are applicable for the current project.

We think this system should be mostly compatible with the use of My in most Visual Basic.NET projects, but please let us know if you encounter any problems or have suggestions for enhancements.