Emitting Symbolic Information with Reflection Emit
Reflection emit allows symbolic information to be defined for a dynamic module. Symbolic information can be defined using the default symbol writer interface or a caller-specified symbol writer interface. Reflection emit provides a convenient high-level abstraction of the low-level symbol writer interfaces in the System.Diagnostics.SymbolStore namespace.
The caller must express an intention that a dynamic module will contain symbolic information by calling the appropriate method to define the dynamic module. The various options for creating dynamic modules with symbolic information are described in Defining a Dynamic Module. It is an error to call a symbol writer method for a dynamic module that has not been created with the intention of containing symbolic information.
Reflection emit provides the following methods for emitting symbolic information:
-
The symbol writer interface associated with a dynamic module can be obtained using the ModuleBuilderGetSymWriter method.
-
The user entry point for a dynamic module can be defined using the ModuleBuilder.SetUserEntryPoint method. The user entry point is the method that the user has identified as the entry point rather than the caller-generated stubs before the main method.
-
Document objects are defined using the ModuleBuilder.DefineDocument method.
-
Custom attributes stored in the symbol store are defined for modules, methods, and constructors using the ModuleBuilder.SetSymCustomAttribute, MethodBuilderSetSymCustomAttribute, and ConstructorBuilderSetSymCustomAttribute methods, respectively.
-
Sequence points are identified using the ILGeneratorMarkSequencePoint method.
-
Lexical scopes are defined using the ILGeneratorBeginScope and ILGeneratorEndScope methods.
-
The name of a local variable in a method or a constructor can be set using the LocalBuilderSetLocalSymInfo method. Optionally, the lexical scope of the local variable can be specified. A LocalBuilder object is obtained by calling ILGeneratorDeclareLocal.