Table of Contents

Class Generator

Namespace
Rinku.Mapping.Emission
Assembly
Rinku.dll

Writes parser instructions and provides reusable local variables. Custom read plans receive this type in their write methods.

public class Generator : ILGenerator
Inheritance
Generator
Inherited Members
Extension Methods

Constructors

Generator(ILGenerator)

Writes parser instructions and provides reusable local variables. Custom read plans receive this type in their write methods.

public Generator(ILGenerator generator)

Parameters

generator ILGenerator

Properties

ILOffset

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

public override int ILOffset { get; }

Property Value

int

The offset in the MSIL stream at which the next instruction will be emitted.

Methods

BeginCatchBlock(Type?)

Begins a catch block.

public override void BeginCatchBlock(Type? exceptionType)

Parameters

exceptionType Type

The Type object that represents the exception.

Exceptions

ArgumentException

The catch block is within a filtered exception.

ArgumentNullException

exceptionType is null, and the exception filter block has not returned a value that indicates that finally blocks should be run until this catch block is located.

NotSupportedException

The Microsoft intermediate language (MSIL) being generated is not currently in an exception block.

BeginExceptFilterBlock()

Begins an exception block for a filtered exception.

public override void BeginExceptFilterBlock()

Exceptions

NotSupportedException

The Microsoft intermediate language (MSIL) being generated is not currently in an exception block.

-or-

This ILGenerator belongs to a DynamicMethod.

BeginExceptionBlock()

Begins an exception block for a non-filtered exception.

public override Label BeginExceptionBlock()

Returns

Label

The label for the end of the block. This will leave you in the correct place to execute finally blocks or to finish the try.

BeginFaultBlock()

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

public override void BeginFaultBlock()

Exceptions

NotSupportedException

The MSIL being generated is not currently in an exception block.

-or-

This ILGenerator belongs to a DynamicMethod.

BeginFinallyBlock()

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

public override void BeginFinallyBlock()

Exceptions

NotSupportedException

The MSIL being generated is not currently in an exception block.

BeginScope()

Begins a lexical scope.

public override void BeginScope()

Exceptions

NotSupportedException

This ILGenerator belongs to a DynamicMethod.

DeclareLocal(Type, bool)

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

public override LocalBuilder DeclareLocal(Type localType, bool pinned)

Parameters

localType Type

A Type object that represents the type of the local variable.

pinned bool

true to pin the object in memory; otherwise, false.

Returns

LocalBuilder

A LocalBuilder object that represents the local variable.

Exceptions

ArgumentNullException

localType is null.

InvalidOperationException

The containing type has been created by the CreateType() method.

-or-

The method body of the enclosing method has been created by the System.Reflection.Emit.MethodBuilder.CreateMethodBody(System.Byte[],System.Int32) method.

NotSupportedException

The method with which this ILGenerator is associated is not represented by a MethodBuilder.

DefineLabel()

Declares a new label.

public override Label DefineLabel()

Returns

Label

A new label that can be used as a token for branching.

Emit(OpCode)

Puts the specified instruction onto the stream of instructions.

public override void Emit(OpCode opcode)

Parameters

opcode OpCode

The Microsoft Intermediate Language (MSIL) instruction to be put onto the stream.

Emit(OpCode, byte)

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

public override void Emit(OpCode opcode, byte arg)

Parameters

opcode OpCode

The MSIL instruction to be put onto the stream.

arg byte

The character argument pushed onto the stream immediately after the instruction.

Emit(OpCode, double)

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

public override void Emit(OpCode opcode, double arg)

Parameters

opcode OpCode

The MSIL instruction to be put onto the stream. Defined in the OpCodes enumeration.

arg double

The numerical argument pushed onto the stream immediately after the instruction.

Emit(OpCode, short)

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

public override void Emit(OpCode opcode, short arg)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

arg short

The Int argument pushed onto the stream immediately after the instruction.

Emit(OpCode, int)

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

public override void Emit(OpCode opcode, int arg)

Parameters

opcode OpCode

The MSIL instruction to be put onto the stream.

arg int

The numerical argument pushed onto the stream immediately after the instruction.

Emit(OpCode, long)

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

public override void Emit(OpCode opcode, long arg)

Parameters

opcode OpCode

The MSIL instruction to be put onto the stream.

arg long

The numerical argument pushed onto the stream immediately after the instruction.

Emit(OpCode, ConstructorInfo)

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

public override void Emit(OpCode opcode, ConstructorInfo con)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

con ConstructorInfo

A ConstructorInfo representing a constructor.

Exceptions

ArgumentNullException

con is null.

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.

public override void Emit(OpCode opcode, Label label)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

label Label

The label to which to branch from this location.

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.

public override void Emit(OpCode opcode, Label[] labels)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

labels Label[]

The array of label objects to which to branch from this location. All of the labels will be used.

Emit(OpCode, LocalBuilder)

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

public override void Emit(OpCode opcode, LocalBuilder local)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

local LocalBuilder

A local variable.

Exceptions

ArgumentException

The parent method of the local parameter does not match the method associated with this ILGenerator.

ArgumentNullException

local is null.

InvalidOperationException

opcode is a single-byte instruction, and local represents a local variable with an index greater than Byte.MaxValue.

Emit(OpCode, SignatureHelper)

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

public override void Emit(OpCode opcode, SignatureHelper signature)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

signature SignatureHelper

A helper for constructing a signature token.

Exceptions

ArgumentNullException

signature is null.

Emit(OpCode, FieldInfo)

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

public override void Emit(OpCode opcode, FieldInfo field)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

field FieldInfo

A FieldInfo representing a field.

Emit(OpCode, MethodInfo)

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

public override void Emit(OpCode opcode, MethodInfo meth)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

meth MethodInfo

A MethodInfo representing a method.

Exceptions

ArgumentNullException

meth is null.

NotSupportedException

meth is a generic method for which the IsGenericMethodDefinition property is false.

Emit(OpCode, float)

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

public override void Emit(OpCode opcode, float arg)

Parameters

opcode OpCode

The MSIL instruction to be put onto the stream.

arg float

The float argument pushed onto the stream immediately after the instruction.

Emit(OpCode, string)

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

public override void Emit(OpCode opcode, string str)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream.

str string

The String to be emitted.

Emit(OpCode, Type)

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

public override void Emit(OpCode opcode, Type cls)

Parameters

opcode OpCode

The MSIL instruction to be put onto the stream.

cls Type

A Type.

Exceptions

ArgumentNullException

cls is null.

EmitCall(OpCode, MethodInfo, Type[]?)

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

public override void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[]? optionalParameterTypes)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream. Must be Call, Callvirt, or Newobj.

methodInfo MethodInfo

The varargs method to be called.

optionalParameterTypes Type[]

The types of the optional arguments if the method is a varargs method; otherwise, null.

Exceptions

ArgumentException

opcode does not specify a method call.

ArgumentNullException

methodInfo is null.

InvalidOperationException

The calling convention for the method is not varargs, but optional parameter types are supplied. This exception is thrown in the .NET Framework versions 1.0 and 1.1, In subsequent versions, no exception is thrown.

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.

public override void EmitCalli(OpCode opcode, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, Type[]? optionalParameterTypes)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream. Must be Calli.

callingConvention CallingConventions

The managed calling convention to be used.

returnType Type

The Type of the result.

parameterTypes Type[]

The types of the required arguments to the instruction.

optionalParameterTypes Type[]

The types of the optional arguments for varargs calls.

Exceptions

InvalidOperationException

optionalParameterTypes is not null, but callingConvention does not include the VarArgs flag.

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.

public override void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type? returnType, Type[]? parameterTypes)

Parameters

opcode OpCode

The MSIL instruction to be emitted onto the stream. Must be Calli.

unmanagedCallConv CallingConvention

The unmanaged calling convention to be used.

returnType Type

The Type of the result.

parameterTypes Type[]

The types of the required arguments to the instruction.

EndExceptionBlock()

Ends an exception block.

public override void EndExceptionBlock()

Exceptions

InvalidOperationException

The end exception block occurs in an unexpected place in the code stream.

NotSupportedException

The Microsoft intermediate language (MSIL) being generated is not currently in an exception block.

EndScope()

Ends a lexical scope.

public override void EndScope()

Exceptions

NotSupportedException

This ILGenerator belongs to a DynamicMethod.

GetLocal(Type)

Gets a local for the given type and reuses one when available.

public LocalBuilder GetLocal(Type type)

Parameters

type Type

Returns

LocalBuilder

MarkLabel(Label)

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

public override void MarkLabel(Label loc)

Parameters

loc Label

The label for which to set an index.

Exceptions

ArgumentException

loc represents an invalid index into the label array.

-or-

An index for loc has already been defined.

UsingNamespace(string)

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

public override void UsingNamespace(string usingNamespace)

Parameters

usingNamespace string

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

Exceptions

ArgumentException

Length of usingNamespace is zero.

ArgumentNullException

usingNamespace is null.

NotSupportedException

This ILGenerator belongs to a DynamicMethod.