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.

System::Object
  System.Reflection.Emit::DynamicILInfo

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public ref class DynamicILInfo

The DynamicILInfo type exposes the following members.

  NameDescription
Public propertyDynamicMethodGets the dynamic method whose body is generated by the current instance.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTokenFor(array<Byte>)Gets a token, valid in the scope of the current DynamicILInfo, representing the signature for the associated dynamic method.
Public methodGetTokenFor(DynamicMethod)Gets a token, valid in the scope of the current DynamicILInfo, representing a dynamic method to be called from the associated method.
Public methodGetTokenFor(RuntimeFieldHandle)Gets a token, valid in the scope of the current DynamicILInfo, representing a field to be accessed from the associated dynamic method.
Public methodGetTokenFor(RuntimeMethodHandle)Gets a token, valid in the scope of the current DynamicILInfo, representing a method to be accessed from the associated dynamic method.
Public methodGetTokenFor(RuntimeTypeHandle)Gets a token, valid in the scope of the current DynamicILInfo, representing a type to be used in the associated dynamic method.
Public methodGetTokenFor(String)Gets a token, valid in the scope of the current DynamicILInfo, representing a string literal to be used in the associated dynamic method.
Public methodGetTokenFor(RuntimeFieldHandle, RuntimeTypeHandle)Gets a token, valid in the scope of the current DynamicILInfo, representing a field to be accessed from the associated dynamic method; the field is on the specified generic type.
Public methodGetTokenFor(RuntimeMethodHandle, RuntimeTypeHandle)Gets a token, valid in the scope of the current DynamicILInfo, representing a method on a generic type.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSetCode(array<Byte>, Int32)Sets the code body of the associated dynamic method.
Public methodSetCode(Byte*, Int32, Int32)Sets the code body of the associated dynamic method.
Public methodSetExceptions(array<Byte>)Sets the exception metadata for the associated dynamic method.
Public methodSetExceptions(Byte*, Int32)Sets the exception metadata for the associated dynamic method.
Public methodSetLocalSignature(array<Byte>)Sets the local variable signature that describes the layout of local variables for the associated dynamic method.
Public methodSetLocalSignature(Byte*, Int32)Sets the local variable signature that describes the layout of local variables for the associated dynamic method.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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

To create instances of other types, call methods, and so on, the MSIL you generate must include tokens for those entities. The DynamicILInfo class provides several overloads of the GetTokenFor method, which return tokens valid in the scope of the current DynamicILInfo. For example, if you need to call an overload of the Console::WriteLine method, you can obtain a RuntimeMethodHandle for that overload and pass it to the 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 SetCode, SetExceptions, and SetLocalSignature methods to insert them into the DynamicMethod associated with your 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 ECMA C# and Common Language Infrastructure Standards on MSDN and Standard ECMA-335 - Common Language Infrastructure (CLI) on the Ecma International Web site.

NoteNote

Do not use DynamicILInfo to generate code that creates a delegate to another dynamic method by calling the delegate constructor directly. Instead, use the CreateDelegate 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.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft