ערוך

שתף באמצעות


ILGenerator Class

Definition

Generates Microsoft intermediate language (MSIL) instructions.

public ref class ILGenerator
public ref class ILGenerator abstract
public ref class ILGenerator : System::Runtime::InteropServices::_ILGenerator
public class ILGenerator
public abstract class ILGenerator
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public class ILGenerator : System.Runtime.InteropServices._ILGenerator
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public class ILGenerator : System.Runtime.InteropServices._ILGenerator
type ILGenerator = class
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type ILGenerator = class
    interface _ILGenerator
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ILGenerator = class
    interface _ILGenerator
Public Class ILGenerator
Public MustInherit Class ILGenerator
Public Class ILGenerator
Implements _ILGenerator
Inheritance
ILGenerator
Attributes
Implements

Remarks

ILGenerator is used to generate method bodies for methods and constructors in dynamic assemblies (represented by the MethodBuilder and ConstructorBuilder classes) and for standalone dynamic methods (represented by the DynamicMethod class). To obtain an ILGenerator, use the ConstructorBuilder.GetILGenerator, DynamicMethod.GetILGenerator, and MethodBuilder.GetILGenerator methods.

MSIL is used as input to a just-in-time (JIT) compiler.

Warning

There are no restrictions, other than basic validation, for ILGenerator APIs that produce method IL. If untrusted input is used for producing IL:

  • IL and metadata can contain secrets provided by the consumer.
  • IL can be invalid, such as not having balanced push versus pop opcodes, or invalid operands for a given opcode.
  • IL can contain any code that might, for example, deadlock, have infinite stack recursion, or have an infinite loop.
  • IL can load and execute code on any other reachable assembly.

Such code can do whatever it wishes when the method is loaded and executed. To protect against such vulnerabilities, ILGenerator requires a fully trusted environment with trusted input.

Constructors

ILGenerator()

Initializes a new instance of the ILGenerator class.

Properties

ILOffset

Gets the current offset, in bytes, in the Microsoft intermediate language (MSIL) stream that is being emitted by the ILGenerator.

Methods

BeginCatchBlock(Type)

Begins a catch block.

BeginExceptFilterBlock()

Begins an exception block for a filtered exception.

BeginExceptionBlock()

Begins an exception block for a non-filtered exception.

BeginFaultBlock()

Begins an exception fault block in the Microsoft intermediate language (MSIL) stream.

BeginFinallyBlock()

Begins a finally block in the Microsoft intermediate language (MSIL) instruction stream.

BeginScope()

Begins a lexical scope.

CreateLabel(Int32)

Creates a Label with the given ID.

DeclareLocal(Type, Boolean)

Declares a local variable of the specified type, optionally pinning the object referred to by the variable.

DeclareLocal(Type)

Declares a local variable of the specified type.

DefineLabel()

Declares a new label.

Emit(OpCode, Byte)

Puts the specified instruction and character argument onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, ConstructorInfo)

Puts the specified instruction and metadata token for the specified constructor onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, Double)

Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, FieldInfo)

Puts the specified instruction and metadata token for the specified field onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, Int16)

Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, Int32)

Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, Int64)

Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, Label)

Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream and leaves space to include a label when fixes are done.

Emit(OpCode, Label[])

Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream and leaves space to include a label when fixes are done.

Emit(OpCode, LocalBuilder)

Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the index of the given local variable.

Emit(OpCode, MethodInfo)

Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the metadata token for the given method.

Emit(OpCode, SByte)

Puts the specified instruction and character argument onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, SignatureHelper)

Puts the specified instruction and a signature token onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, Single)

Puts the specified instruction and numerical argument onto the Microsoft intermediate language (MSIL) stream of instructions.

Emit(OpCode, String)

Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the metadata token for the given string.

Emit(OpCode, Type)

Puts the specified instruction onto the Microsoft intermediate language (MSIL) stream followed by the metadata token for the given type.

Emit(OpCode)

Puts the specified instruction onto the stream of instructions.

EmitCall(OpCode, MethodInfo, Type[])

Puts a call or callvirt instruction onto the Microsoft intermediate language (MSIL) stream to call a varargs method.

EmitCalli(OpCode, CallingConvention, Type, Type[])

Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream, specifying an unmanaged calling convention for the indirect call.

EmitCalli(OpCode, CallingConventions, Type, Type[], Type[])

Puts a Calli instruction onto the Microsoft intermediate language (MSIL) stream, specifying a managed calling convention for the indirect call.

EmitWriteLine(FieldInfo)

Emits the Microsoft intermediate language (MSIL) necessary to call WriteLine with the given field.

EmitWriteLine(LocalBuilder)

Emits the Microsoft intermediate language (MSIL) necessary to call WriteLine with the given local variable.

EmitWriteLine(String)

Emits the Microsoft intermediate language (MSIL) to call WriteLine with a string.

EndExceptionBlock()

Ends an exception block.

EndScope()

Ends a lexical scope.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MarkLabel(Label)

Marks the Microsoft intermediate language (MSIL) stream's current position with the given label.

MarkSequencePoint(ISymbolDocumentWriter, Int32, Int32, Int32, Int32)

Marks a sequence point in the Microsoft intermediate language (MSIL) stream.

MarkSequencePointCore(ISymbolDocumentWriter, Int32, Int32, Int32, Int32)

When overridden in a derived class, marks a sequence point in the Microsoft intermediate language (MSIL) stream.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ThrowException(Type)

Emits an instruction to throw an exception.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
UsingNamespace(String)

Specifies the namespace to be used in evaluating locals and watches for the current active lexical scope.

Explicit Interface Implementations

_ILGenerator.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.

_ILGenerator.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can then be used to get the type information for an interface.

_ILGenerator.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

_ILGenerator.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.

Applies to