Class Generator
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
generatorILGenerator
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
Exceptions
- ArgumentException
The catch block is within a filtered exception.
- ArgumentNullException
exceptionTypeis 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
Returns
- LocalBuilder
A LocalBuilder object that represents the local variable.
Exceptions
- ArgumentNullException
localTypeis 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
opcodeOpCodeThe 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
opcodeOpCodeThe MSIL instruction to be put onto the stream.
argbyteThe 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
opcodeOpCodeThe MSIL instruction to be put onto the stream. Defined in the
OpCodesenumeration.argdoubleThe 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
argshortThe
Intargument 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
opcodeOpCodeThe MSIL instruction to be put onto the stream.
argintThe 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
opcodeOpCodeThe MSIL instruction to be put onto the stream.
arglongThe 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
conConstructorInfoA
ConstructorInforepresenting a constructor.
Exceptions
- ArgumentNullException
conis 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
labelLabelThe 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
labelsLabel[]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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
localLocalBuilderA local variable.
Exceptions
- ArgumentException
The parent method of the
localparameter does not match the method associated with this ILGenerator.- ArgumentNullException
localis null.- InvalidOperationException
opcodeis a single-byte instruction, andlocalrepresents a local variable with an index greater thanByte.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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
signatureSignatureHelperA helper for constructing a signature token.
Exceptions
- ArgumentNullException
signatureis 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
fieldFieldInfoA
FieldInforepresenting 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
methMethodInfoA
MethodInforepresenting a method.
Exceptions
- ArgumentNullException
methis null.- NotSupportedException
methis 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
opcodeOpCodeThe MSIL instruction to be put onto the stream.
argfloatThe 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream.
strstringThe
Stringto 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
Exceptions
- ArgumentNullException
clsis 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream. Must be Call, Callvirt, or Newobj.
methodInfoMethodInfoThe
varargsmethod to be called.optionalParameterTypesType[]The types of the optional arguments if the method is a
varargsmethod; otherwise, null.
Exceptions
- ArgumentException
opcodedoes not specify a method call.- ArgumentNullException
methodInfois 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream. Must be Calli.
callingConventionCallingConventionsThe managed calling convention to be used.
returnTypeTypeThe Type of the result.
parameterTypesType[]The types of the required arguments to the instruction.
optionalParameterTypesType[]The types of the optional arguments for
varargscalls.
Exceptions
- InvalidOperationException
optionalParameterTypesis not null, butcallingConventiondoes 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
opcodeOpCodeThe MSIL instruction to be emitted onto the stream. Must be Calli.
unmanagedCallConvCallingConventionThe unmanaged calling convention to be used.
returnTypeTypeThe Type of the result.
parameterTypesType[]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
typeType
Returns
MarkLabel(Label)
Marks the Microsoft intermediate language (MSIL) stream's current position with the given label.
public override void MarkLabel(Label loc)
Parameters
locLabelThe label for which to set an index.
Exceptions
- ArgumentException
locrepresents an invalid index into the label array.-or-
An index for
lochas 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
usingNamespacestringThe namespace to be used in evaluating locals and watches for the current active lexical scope.
Exceptions
- ArgumentException
Length of
usingNamespaceis zero.- ArgumentNullException
usingNamespaceis null.- NotSupportedException
This ILGenerator belongs to a DynamicMethod.