System.Reflection.Emit.DynamicILInfo Class

Provides support for alternative ways to generate the Microsoft intermediate language (MSIL) and metadata for a dynamic method, including methods for creating tokens and for inserting the code, exception handling, and local variable signature blobs.

See Also: DynamicILInfo Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public class DynamicILInfo

Remarks

The System.Reflection.Emit.DynamicILInfo class allows developers to write their own MSIL generators instead of using System.Reflection.Emit.ILGenerator.

To create instances of other types, call methods, and so on, the MSIL you generate must include tokens for those entities. The System.Reflection.Emit.DynamicILInfo class provides several overloads of the erload:System.Reflection.Emit.DynamicILInfo.GetTokenFor method, which return tokens valid in the scope of the current System.Reflection.Emit.DynamicILInfo. For example, if you need to call an overload of the erload:System.Console.WriteLine method, you can obtain a RuntimeMethodHandle for that overload and pass it to the erload:System.Reflection.Emit.DynamicILInfo.GetTokenFor method to obtain a token to embed in your MSIL.

Once you have created byte arrays for your local variable signature, exceptions, and code body, you can use the erload:System.Reflection.Emit.DynamicILInfo.SetCode, erload:System.Reflection.Emit.DynamicILInfo.SetExceptions, and erload:System.Reflection.Emit.DynamicILInfo.SetLocalSignature methods to insert them into the System.Reflection.Emit.DynamicMethod associated with your System.Reflection.Emit.DynamicILInfo object.

Generating your own metadata and MSIL requires familiarity with the Common Language Infrastructure (CLI) documentation, especially "Partition II: Metadata Definition and Semantics" and "Partition III: CIL Instruction Set". The documentation is available online; see tp://go.microsoft.com/fwlink/?LinkID=99212 on MSDN and tp://go.microsoft.com/fwlink/?LinkID=65552 on the Ecma International Web site.

Note:

Do not use System.Reflection.Emit.DynamicILInfo to generate code that creates a delegate to another dynamic method by calling the delegate constructor directly. Instead, use the DynamicMethod.CreateDelegate(Type) method to create the delegate. A delegate that is created with the delegate constructor does not have a reference to the target dynamic method. The dynamic method might be reclaimed by garbage collection while the delegate is still in use.

Requirements

Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0