Show / Hide Table of Contents

Class ILGeneratorExtensions

Contains useful extensions for code generation via the ILGenerator class.

Inheritance
object
ILGeneratorExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: TheXDS.MCART.Types.Extensions
Assembly: MCART.TypeFactory.dll
Syntax
public static class ILGeneratorExtensions

Methods

| Edit this page View Source

Add(ILGenerator)

Inserts an addition operation into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Add(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

This method expects two values on the stack that can be added together.

| Edit this page View Source

Branch(ILGenerator, Label)

Inserts an unconditional control‑transfer jump into the MSIL instruction sequence to a label.

Declaration
public static ILGenerator Branch(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

Label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

BranchEqual(ILGenerator, Label)

Inserts a conditional branch to a label in a Microsoft® IL sequence, branching when the top two stack values are equal.

Declaration
public static ILGenerator BranchEqual(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The label that will become the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchEqualNewLabel(ILGenerator, out Label)

Inserts a conditional branch to a new label in a Microsoft® IL sequence, branching when the top two stack values are equal.

Declaration
public static ILGenerator BranchEqualNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The new label that will become the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchFalse(ILGenerator, Label)

Inserts a conditional control‑transfer jump into the Microsoft Intermediate Language (MSIL) instruction sequence to a new label, jumping if the value on top of the stack evaluates to false.

Declaration
public static ILGenerator BranchFalse(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

Label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

BranchFalseNewLabel(ILGenerator, out Label)

Inserts a conditional control‑transfer jump into the MSIL instruction sequence to a new label, jumping if the value on top of the stack evaluates to false.

Declaration
public static ILGenerator BranchFalseNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

New label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

BranchGreaterThan(ILGenerator, Label)

Inserts a conditional control‑transfer jump into the MSIL instruction sequence to a new label; jumping if, after comparing the two values on top of the stack, the first is greater than the second.

Declaration
public static ILGenerator BranchGreaterThan(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

Label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

BranchGreaterThanNewLabel(ILGenerator, out Label)

Inserts a conditional control‑transfer jump into the MSIL instruction sequence to a new label; jumping if, after comparing the two values on top of the stack, the first is greater than the second.

Declaration
public static ILGenerator BranchGreaterThanNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

New label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

BranchGreaterThanOrEqual(ILGenerator, Label)

Inserts a conditional branch to a label in a Microsoft® IL sequence, branching when the top two stack values are compared and the first is greater than or equal to the second.

Declaration
public static ILGenerator BranchGreaterThanOrEqual(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The label that will become the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchGreaterThanOrEqualNewLabel(ILGenerator, out Label)

Inserts a conditional branch to a new label in a Microsoft® IL sequence, branching when the top two stack values are compared and the first is greater than or equal to the second.

Declaration
public static ILGenerator BranchGreaterThanOrEqualNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The new label that will become the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchLessThan(ILGenerator, Label)

Inserts a conditional control‑transfer jump into the MSIL instruction sequence to a new label; jumping if, after comparing the two values on top of the stack, the first is less than the second.

Declaration
public static ILGenerator BranchLessThan(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

Label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

BranchLessThanNewLabel(ILGenerator, out Label)

Inserts a conditional branch to a new label in a Microsoft® IL sequence, branching when the top two stack values are compared and the first is less than the second.

Declaration
public static ILGenerator BranchLessThanNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The new label that will become the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchLessThanOrEqual(ILGenerator, Label)

Inserts a conditional branch in a Microsoft® IL sequence to a new label, branching when the top two stack values are compared and the first is less than or equal to the second.

Declaration
public static ILGenerator BranchLessThanOrEqual(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The label that will be the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchLessThanOrEqualNewLabel(ILGenerator, out Label)

Inserts a conditional branch in a Microsoft® IL sequence to a new label, branching when the top two stack values are compared and the first is less than or equal to the second.

Declaration
public static ILGenerator BranchLessThanOrEqualNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The new label that will be the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchNewLabel(ILGenerator, out Label)

Inserts an unconditional branch in a Microsoft® IL sequence to a new label.

Declaration
public static ILGenerator BranchNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The new label that will be the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchNotEqual(ILGenerator, Label)

Inserts a conditional branch in a Microsoft® IL sequence to a new label, branching when the top two stack values are compared and the first is not equal to the second.

Declaration
public static ILGenerator BranchNotEqual(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The label that will be the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchNotEqualNewLabel(ILGenerator, out Label)

Inserts a conditional branch in a Microsoft® IL sequence to a new label, branching when the top two stack values are compared and the first is not equal to the second.

Declaration
public static ILGenerator BranchNotEqualNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator where the branch will be inserted.

Label label

The new label that will be the branch destination.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

BranchTrue(ILGenerator, Label)

Inserts a conditional control‑transfer jump into the MSIL instruction sequence to a new label, jumping if the value on top of the stack evaluates to true.

Declaration
public static ILGenerator BranchTrue(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

Label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

BranchTrueNewLabel(ILGenerator, out Label)

Inserts a conditional control‑transfer jump into the MSIL instruction sequence to a new label, jumping if the value on top of the stack evaluates to true.

Declaration
public static ILGenerator BranchTrueNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the jump.

Label label

New label that will be the target of the jump.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

Call(ILGenerator, MethodInfo)

Inserts a call to the specified method.

Declaration
public static ILGenerator Call(this ILGenerator ilGen, MethodInfo method)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the method call is inserted.

MethodInfo method

Method to call.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

CallBaseCtor<TClass>(ILGenerator)

Inserts a call to the parameterless base type instance constructor into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CallBaseCtor<TClass>(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence in which to insert the base constructor call.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
TClass

Class from which the base type constructor will be called.

| Edit this page View Source

CallBaseCtor<TClass>(ILGenerator, Type[], Action<ILGenerator>?)

Inserts a call to the specified base type instance constructor into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CallBaseCtor<TClass>(this ILGenerator ilGen, Type[] baseCtorArgs, Action<ILGenerator>? parameterLoadCallback)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence in which to insert the base constructor call.

Type[] baseCtorArgs

Array of argument types for the constructor to call.

Action<ILGenerator> parameterLoadCallback

Callback to insert the loading of arguments to pass to the base constructor.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
TClass

Class from which the base type constructor will be called.

Remarks

When calling this method, the current reference (LoadArg0(ILGenerator)) will automatically be inserted when baseCtorArgs is not empty and parameterLoadCallback refers to a method that loads the constructor arguments, or when baseCtorArgs is empty and parameterLoadCallback is null. Otherwise, you must insert the loading of Arg0 and all arguments before performing this call.

| Edit this page View Source

CallVirt(ILGenerator, MethodInfo)

Inserts an explicitly virtual call to the specified method.

Declaration
public static ILGenerator CallVirt(this ILGenerator ilGen, MethodInfo method)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the call is inserted.

MethodInfo method

Method to call.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

Call<TMethod>(ILGenerator, Expression<Func<TMethod>>)

Inserts a call to the specified static method into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Call<TMethod>(this ILGenerator ilGen, Expression<Func<TMethod>> methodSelector) where TMethod : Delegate
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the static method call is inserted.

Expression<Func<TMethod>> methodSelector

Expression that selects the static method to call.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
TMethod

Delegate that describes the method to call.

| Edit this page View Source

Call<TMethod>(ILGenerator, TMethod)

Inserts a call to the specified static method into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Call<TMethod>(this ILGenerator ilGen, TMethod method) where TMethod : Delegate
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the static method call is inserted.

TMethod method

Static method to call.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
TMethod

Delegate that describes the method to call.

| Edit this page View Source

Call<TClass, TMethod>(ILGenerator, Expression<Func<TClass, TMethod>>)

Inserts a call to the specified instance method into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Call<TClass, TMethod>(this ILGenerator ilGen, Expression<Func<TClass, TMethod>> methodSelector) where TMethod : Delegate
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence in which to insert the instance method call.

Expression<Func<TClass, TMethod>> methodSelector

Expression that selects the instance method to call.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
TClass

Class in which the instance method resides.

TMethod

Delegate that describes the method to call.

| Edit this page View Source

CastAsByte(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a byte in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsByte(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

CastAsDouble(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a double in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsDouble(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CastAsFloat(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a float in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsFloat(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CastAsInt(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a int in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsInt(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CastAsLong(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a long in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsLong(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CastAsSByte(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a sbyte in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsSByte(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

CastAsShort(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a short in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsShort(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CastAsUInt(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a uint in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsUInt(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CastAsULong(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a ulong in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsULong(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CastAsUShort(ILGenerator)

Inserts an operation that converts the value at the top of the stack to a ushort in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CastAsUShort(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing fluent syntax.

| Edit this page View Source

CompareEqual(ILGenerator)

Inserts an equality comparison operation between two values at the top of the stack into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CompareEqual(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

CompareGreaterThan(ILGenerator)

Inserts a greater‑than comparison operation between two values at the top of the stack into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CompareGreaterThan(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

CompareLessThan(ILGenerator)

Inserts a less‑than comparison operation between two values at the top of the stack into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator CompareLessThan(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

Dispose(ILGenerator, LocalBuilder)

Disposes an IDisposable object contained in the specified LocalBuilder.

Declaration
public static ILGenerator Dispose(this ILGenerator ilGen, LocalBuilder disposable)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the call is inserted.

LocalBuilder disposable

Local variable that holds the IDisposable to dispose.

Returns
Type Description
ILGenerator
| Edit this page View Source

Divide(ILGenerator)

Inserts a division operation into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Divide(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

This method expects two values on the stack that can be divided.

| Edit this page View Source

Duplicate(ILGenerator)

Inserts a duplicate operation that copies the value at the top of the stack into the Microsoft® Intermediate Language (MSIL) instruction stream.

Declaration
public static ILGenerator Duplicate(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

For(ILGenerator, int, int, ForBlock)

Inserts a simple structured for block with an int accumulator into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator For(this ILGenerator ilGen, int startValue, int endValue, ILGeneratorExtensions.ForBlock forBlock)
Parameters
Type Name Description
ILGenerator ilGen

The IL instruction sequence into which the for block will be inserted.

int startValue

The inclusive starting value of the accumulator.

int endValue

The inclusive ending value of the accumulator.

ILGeneratorExtensions.ForBlock forBlock

Action that defines the instructions to execute inside the for block. It receives the LocalBuilder of the accumulator and a label that can be used as the exit label to break the loop.

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

| Edit this page View Source

For(ILGenerator, LocalBuilder, object?, Action<ILGenerator>, Action<ILGenerator>, ForBlock)

Inserts a structured for block into the Microsoft® IL instruction sequence.

Declaration
public static ILGenerator For(this ILGenerator ilGen, LocalBuilder accumulator, object? initialValue, Action<ILGenerator> condition, Action<ILGenerator> incrementor, ILGeneratorExtensions.ForBlock forBlock)
Parameters
Type Name Description
ILGenerator ilGen

ILGenerator where the for block will be inserted.

LocalBuilder accumulator

Local variable used as the accumulator for the for block.

object initialValue

Value used to initialize the accumulator.

Action<ILGenerator> condition

Action that defines the initial evaluation of the for block.

Action<ILGenerator> incrementor

Action that defines the increment operation to execute at the end of each for iteration.

ILGeneratorExtensions.ForBlock forBlock

Action that defines the statements to execute inside the for block. The action receives a parameter that can be used as the exit label to terminate the block.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

For(ILGenerator, Range<int>, ForBlock)

Inserts a simple structured for block with an int accumulator into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator For(this ILGenerator ilGen, Range<int> range, ILGeneratorExtensions.ForBlock forBlock)
Parameters
Type Name Description
ILGenerator ilGen

The IL instruction sequence into which the for block will be inserted.

Range<int> range

The range of values to use for the accumulator.

ILGeneratorExtensions.ForBlock forBlock

Action that defines the instructions to execute inside the for block. It receives the LocalBuilder of the accumulator and a label that can be used as the exit label to break the loop.

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

| Edit this page View Source

ForEach<T>(ILGenerator, ForEachBlock)

Inserts a structured foreach block into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator ForEach<T>(this ILGenerator ilGen, ILGeneratorExtensions.ForEachBlock foreachBlock)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the foreach block will be inserted.

ILGeneratorExtensions.ForEachBlock foreachBlock

Delegate that defines the actions to execute inside the foreach block. The action receives a reference to the LocalBuilder representing the current element.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T
Remarks

This instruction expects the value on the top of the stack to implement IEnumerable<T>.

| Edit this page View Source

For<T>(ILGenerator, T, Action<LocalBuilder>, Action<LocalBuilder>, ForBlock)

Inserts a structured for block into the Microsoft® IL instruction sequence.

Declaration
public static ILGenerator For<T>(this ILGenerator ilGen, T initialValue, Action<LocalBuilder> condition, Action<LocalBuilder> incrementor, ILGeneratorExtensions.ForBlock forBlock)
Parameters
Type Name Description
ILGenerator ilGen

ILGenerator where the for block will be inserted.

T initialValue

Initial value of the accumulator for the for block.

Action<LocalBuilder> condition

Action that defines the initial evaluation of the for block. The action receives a reference to the FieldBuilder of the accumulator.

Action<LocalBuilder> incrementor

Action that defines the increment operation to execute at the end of each for iteration. The action receives a reference to the FieldBuilder of the accumulator.

ILGeneratorExtensions.ForBlock forBlock

Action that defines the statements to execute inside the for block. The action receives a reference to the FieldBuilder of the accumulator and a parameter that can be used as the exit label to terminate the block.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T
| Edit this page View Source

For<T>(ILGenerator, T, Action<LocalBuilder>, ForBlock)

Inserts a structured for block into the Microsoft® IL instruction sequence.

Declaration
public static ILGenerator For<T>(this ILGenerator ilGen, T initialValue, Action<LocalBuilder> condition, ILGeneratorExtensions.ForBlock forBlock)
Parameters
Type Name Description
ILGenerator ilGen

ILGenerator where the for block will be inserted.

T initialValue

Initial value of the accumulator for the for block.

Action<LocalBuilder> condition

Action that defines the initial evaluation of the for block. The action receives a reference to the FieldBuilder of the accumulator.

ILGeneratorExtensions.ForBlock forBlock

Action that defines the statements to execute inside the for block. The action receives a reference to the FieldBuilder of the accumulator and a parameter that can be used as the exit label to terminate the block.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T
| Edit this page View Source

GetArrayLength(ILGenerator)

Inserts an operation that retrieves the number of elements contained in an array in the Microsoft® Intermediate Language (MSIL) instruction stream, equivalent to Length.

Declaration
public static ILGenerator GetArrayLength(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

The stack must contain a reference to an array at the top when this call is made. An int value will be pushed onto the top of the stack.

| Edit this page View Source

GetField(ILGenerator, FieldInfo)

Inserts the load of a field value into the MSIL instruction sequence.

Declaration
public static ILGenerator GetField(this ILGenerator ilGen, FieldInfo field)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator sequence where the value load will be inserted.

FieldInfo field

The field from which to load the value.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

Remarks

This method automatically determines whether a reference to this (Me in Visual Basic) is required when the field is static; therefore, it should not insert a call to load the instance (LoadArg0(ILGenerator)).

Net stack effect: -1

| Edit this page View Source

If(ILGenerator, Action<ILGenerator>)

Inserts a structured if block into the Microsoft® IL instruction sequence.

Declaration
public static ILGenerator If(this ILGenerator ilGen, Action<ILGenerator> trueBranch)
Parameters
Type Name Description
ILGenerator ilGen

ILGenerator where the if block will be inserted.

Action<ILGenerator> trueBranch

Action that defines the instructions to insert when the top value on the stack evaluates to true.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

If(ILGenerator, Action<ILGenerator>, Action<ILGenerator>)

Inserts a structured if block into the Microsoft® IL instruction sequence.

Declaration
public static ILGenerator If(this ILGenerator ilGen, Action<ILGenerator> trueBranch, Action<ILGenerator> falseBranch)
Parameters
Type Name Description
ILGenerator ilGen

ILGenerator where the if block will be inserted.

Action<ILGenerator> trueBranch

Action that defines the instructions to insert when the top value on the stack evaluates to true.

Action<ILGenerator> falseBranch

Action that defines the instructions to insert when the top value evaluates to false.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

Increment(ILGenerator)

Inserts a series of instructions that will increment the value on the stack by 1 in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator Increment(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operations.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

Increment(ILGenerator, LocalBuilder)

Inserts a series of instructions that will increment the value of a local variable by 1 in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator Increment(this ILGenerator ilGen, LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operations.

LocalBuilder local

Reference to the local variable on which to perform the increment operation.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

InitLocal(ILGenerator, LocalBuilder, object?)

Inserts the initialization of a local variable in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator InitLocal(this ILGenerator ilGen, LocalBuilder local, object? value)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the local variable initialization.

LocalBuilder local

The local variable in which to store the value.

object value

The constant value to store in the local variable.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

InitNewLocal<T>(ILGenerator, T, out LocalBuilder)

Inserts the initialization of a new local variable in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator InitNewLocal<T>(this ILGenerator ilGen, T value, out LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the local variable initialization.

T value

The constant value to store in the local variable.

LocalBuilder local

The local variable in which to store the value.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T
| Edit this page View Source

InsertNewLabel(ILGenerator, out Label)

Defines and inserts a new label into the Microsoft Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator InsertNewLabel(this ILGenerator ilGen, out Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the new label.

Label label

Label that has been defined and inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

Leave(ILGenerator, Label)

Inserts an unconditional control‑transfer instruction that exits a protected code region (typically a try or catch block) into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator Leave(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the jump will be inserted.

Label label

Destination label for the jump.

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

| Edit this page View Source

LoadArg(ILGenerator, short)

Inserts the load of an argument into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadArg(this ILGenerator ilGen, short argIndex)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance into which the operation will be inserted.

short argIndex

Index of the argument to load onto the stack. A value of 0 will load a reference to the current instance (the value this) when called from an instance method, causing the method parameters to start at index 1.

Returns
Type Description
ILGenerator

The same ilGen instance, allowing fluent syntax.

Remarks

Net stack usage: 1.

| Edit this page View Source

LoadArg0(ILGenerator)

Inserts the load of argument with index 0 of a method into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadArg0(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the operation will be inserted.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

For instance methods, this call loads a reference to the current instance; for static methods it loads the first parameter.

Net stack usage: 1

| Edit this page View Source

LoadArg1(ILGenerator)

Inserts the load of argument with index 1 of a method into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadArg1(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the operation will be inserted.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

For instance methods, this call loads the first argument of the method; for static methods it loads the second parameter.

Net stack usage: 1

| Edit this page View Source

LoadArg2(ILGenerator)

Inserts the load of argument with index 2 of a method into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadArg2(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the operation will be inserted.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

For instance methods, this call loads the second argument of the method; for static methods it loads the third parameter.

Net stack usage: 1

| Edit this page View Source

LoadArg3(ILGenerator)

Inserts the load of the third argument of a method into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadArg3(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the operation will be inserted.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

For instance methods, this call loads the third argument of the method; for static methods it loads the fourth parameter.

Net stack usage: 1

| Edit this page View Source

LoadArgAddress(ILGenerator, short)

Inserts the load of a reference to an argument into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadArgAddress(this ILGenerator ilGen, short argIndex)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance into which the operation will be inserted.

short argIndex

Index of the argument for which to load a reference. A value of 0 will load a reference to the current instance (the value this).

Returns
Type Description
ILGenerator

The same ilGen instance, allowing fluent syntax.

| Edit this page View Source

LoadConstant(ILGenerator, object?)

Inserts a constant in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadConstant(this ILGenerator ilGen, object? value)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the constant load.

object value

The constant value to insert.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Exceptions
Type Condition
NotImplementedException

Thrown when attempting to load an unknown constant value.

InvalidOperationException

Thrown when attempting to load a non-constant value, such as an object instance.

ArgumentNullException

Thrown if value is null. To load a null constant value, use the LoadNull(ILGenerator) method instead.

| Edit this page View Source

LoadConstant(ILGenerator, Type, object?)

Inserts a constant in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadConstant(this ILGenerator ilGen, Type t, object? value)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the constant load.

Type t

The type of constant value to insert.

object value

The constant value to insert.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Exceptions
Type Condition
NotImplementedException

Thrown when attempting to load an unknown constant value.

InvalidOperationException

Thrown when attempting to load a non-constant value, such as an object instance.

| Edit this page View Source

LoadConstant<T>(ILGenerator, T)

Inserts a constant in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadConstant<T>(this ILGenerator ilGen, T value)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the constant load.

T value

The constant value to insert.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

The type of constant value to insert.

Exceptions
Type Condition
NotImplementedException

Thrown when attempting to load an unknown constant value.

InvalidOperationException

Thrown when attempting to load a non-constant value, such as an object instance.

| Edit this page View Source

LoadField(ILGenerator, FieldInfo)

Inserts the load of a field value into the MSIL instruction sequence.

Declaration
public static ILGenerator LoadField(this ILGenerator ilGen, FieldInfo field)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator sequence where the value load will be inserted.

FieldInfo field

The field from which to load the value.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

Remarks

This method automatically determines whether a reference to this (Me in Visual Basic) is required when the field is static; therefore, it should not insert a call to load the instance (LoadArg0(ILGenerator)).

Net stack effect: -1

| Edit this page View Source

LoadFieldAddress(ILGenerator, FieldInfo)

Inserts the load of the address of a field into the IL sequence.

Declaration
public static ILGenerator LoadFieldAddress(this ILGenerator ilGen, FieldInfo field)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the field address will be loaded.

FieldInfo field

The field for which the address is loaded.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

| Edit this page View Source

LoadLocal(ILGenerator, LocalBuilder)

Inserts the loading of a local variable's value into the MSIL instruction sequence.

Declaration
public static ILGenerator LoadLocal(this ILGenerator ilGen, LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance where the value load will be inserted.

LocalBuilder local

Local variable from which to load the value.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

| Edit this page View Source

LoadLocalAddress(ILGenerator, LocalBuilder)

Inserts the loading of a local variable's address into the MSIL instruction sequence.

Declaration
public static ILGenerator LoadLocalAddress(this ILGenerator ilGen, LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance where the address load will be inserted.

LocalBuilder local

Local variable for which to load the reference.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

| Edit this page View Source

LoadNull(ILGenerator)

Inserts a load operation of the constant null in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadNull(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operation.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

LoadParameter(ILGenerator, ParameterInfo)

Inserts the load of a parameter into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadParameter(this ILGenerator ilGen, ParameterInfo parameter)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance into which the operation will be inserted.

ParameterInfo parameter

The parameter to load.

Returns
Type Description
ILGenerator

The same ilGen instance, allowing fluent syntax.

| Edit this page View Source

LoadProperty(ILGenerator, PropertyInfo)

Inserts the load of a property value into the IL sequence.

Declaration
public static ILGenerator LoadProperty(this ILGenerator ilGen, PropertyInfo property)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the property value will be loaded.

PropertyInfo property

The property from which the value is loaded.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

| Edit this page View Source

LoadProperty(ILGenerator, PropertyBuildInfo)

Inserts the load of a property value into the IL sequence.

Declaration
public static ILGenerator LoadProperty(this ILGenerator ilGen, PropertyBuildInfo property)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the property value will be loaded.

PropertyBuildInfo property

The property from which the value is loaded.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

| Edit this page View Source

LoadProperty<T>(ILGenerator, Expression<Func<T, object?>>)

Inserts the load of a property value into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator LoadProperty<T>(this ILGenerator ilGen, Expression<Func<T, object?>> propertySelector)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the property value will be loaded.

Expression<Func<T, object>> propertySelector

Expression indicating which property of the type should be returned.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

Type of object from which the property to load is selected.

| Edit this page View Source

Multiply(ILGenerator)

Inserts a multiplication operation into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Multiply(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

This method expects two values on the stack that can be multiplied together.

| Edit this page View Source

NewArray(ILGenerator, int, Type, out LocalBuilder)

Inserts a one-dimensional array initialization operation of the specified type in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
[RequiresDynamicCode("The method makes calls to dynamic code, so it is not compatible with trimming.")]
public static ILGenerator NewArray(this ILGenerator ilGen, int length, Type arrayType, out LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operation.

int length

The number of elements that the array should contain.

Type arrayType

The type of the new array.

LocalBuilder local

Parameter that contains the local variable generated to store the new array.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

The operation requires the stack to contain the number of elements that the array should contain, expressed as an int value.

Net stack usage: -1

| Edit this page View Source

NewArray(ILGenerator, Type)

Inserts a one-dimensional array initialization operation of the specified type in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator NewArray(this ILGenerator ilGen, Type arrayType)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operation.

Type arrayType

The type of the new array.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

The operation requires the stack to contain the number of elements that the array should contain, expressed as an int value.

Net stack usage: 0

| Edit this page View Source

NewArray(ILGenerator, Type, out LocalBuilder)

Inserts a one-dimensional array initialization operation of the specified type in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
[RequiresDynamicCode("The method makes calls to dynamic code, so it is not compatible with trimming.")]
public static ILGenerator NewArray(this ILGenerator ilGen, Type arrayType, out LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operation.

Type arrayType

The type of the new array.

LocalBuilder local

Parameter that contains the local variable generated to store the new array.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

NewArray<T>(ILGenerator)

Inserts a one-dimensional array initialization operation of the specified type in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator NewArray<T>(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operation.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

The type of the new array.

Remarks

The operation requires the stack to contain the number of elements that the array should contain, expressed as an int value.

Net stack usage: 0

| Edit this page View Source

NewArray<T>(ILGenerator, int, out LocalBuilder)

Inserts a one-dimensional array initialization operation of the specified type in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
[RequiresDynamicCode("The method makes calls to dynamic code, so it is not compatible with trimming.")]
public static ILGenerator NewArray<T>(this ILGenerator ilGen, int length, out LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operation.

int length

The number of elements that the array should contain.

LocalBuilder local

Parameter that contains the local variable generated to store the new array.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

The type of the new array.

Remarks

The operation requires the stack to contain the number of elements that the array should contain, expressed as an int value.

Net stack usage: -1

| Edit this page View Source

NewArray<T>(ILGenerator, out LocalBuilder)

Inserts a one-dimensional array initialization operation of the specified type in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
[RequiresDynamicCode("The method makes calls to dynamic code, so it is not compatible with trimming.")]
public static ILGenerator NewArray<T>(this ILGenerator ilGen, out LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the operation.

LocalBuilder local

Parameter that contains the local variable generated to store the new array.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

The type of the new array.

Remarks

The operation requires the stack to contain the number of elements that the array should contain, expressed as an int value.

Net stack usage: -1

| Edit this page View Source

NewObj(ILGenerator, Type)

Inserts an object instantiation operation in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator NewObj(this ILGenerator ilGen, Type newObjectType)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the object instantiation.

Type newObjectType

The type of object to instantiate.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

NewObj<T>(ILGenerator)

Inserts an object instantiation operation in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator NewObj<T>(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the object instantiation.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

The type of object to instantiate.

| Edit this page View Source

NewObject(ILGenerator, Type)

Inserts the instantiation of an object into the Microsoft® Intermediate Language (MSIL) stream.

Declaration
public static ILGenerator NewObject(this ILGenerator ilGen, Type type)
Parameters
Type Name Description
ILGenerator ilGen

The instruction stream where the object instantiation will be inserted.

Type type

The type of object to instantiate.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for Fluent syntax usage.

Exceptions
Type Condition
ClassNotInstantiableException

Thrown if the class is not instantiable, or if there is no constructor that accepts the specified arguments. It may also occur if one of the parameters is an object that does not have a parameterless constructor, in which case the exception will indicate the type that cannot be instantiated.

| Edit this page View Source

NewObject(ILGenerator, Type, IEnumerable)

Inserts the instantiation of an object into the Microsoft® Intermediate Language (MSIL) stream.

Declaration
public static ILGenerator NewObject(this ILGenerator ilGen, Type type, IEnumerable args)
Parameters
Type Name Description
ILGenerator ilGen

The instruction stream where the object instantiation will be inserted.

Type type

The type of object to instantiate.

IEnumerable args

Arguments to pass to the object's constructor.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for Fluent syntax usage.

Exceptions
Type Condition
ClassNotInstantiableException

Thrown if the class is not instantiable, or if there is no constructor that accepts the specified arguments. It may also occur if one of the parameters is an object that does not have a parameterless constructor, in which case the exception will indicate the type that cannot be instantiated.

| Edit this page View Source

NewObject(ILGenerator, Type, object?[])

Inserts the instantiation of an object into the Microsoft® Intermediate Language (MSIL) stream.

Declaration
public static ILGenerator NewObject(this ILGenerator ilGen, Type type, object?[] args)
Parameters
Type Name Description
ILGenerator ilGen

The instruction stream where the object instantiation will be inserted.

Type type

The type of object to instantiate.

object[] args

Arguments to pass to the object's constructor.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for Fluent syntax usage.

Exceptions
Type Condition
ClassNotInstantiableException

Thrown if the class is not instantiable, or if there is no constructor that accepts the specified arguments. It may also occur if one of the parameters is an object that does not have a parameterless constructor, in which case the exception will indicate the type that cannot be instantiated.

| Edit this page View Source

NewObject(ILGenerator, Type, Type[])

Inserts the instantiation of an object into the Microsoft® Intermediate Language (MSIL) stream.

Declaration
public static ILGenerator NewObject(this ILGenerator ilGen, Type type, Type[] args)
Parameters
Type Name Description
ILGenerator ilGen

The instruction stream where the object instantiation will be inserted.

Type type

The type of object to instantiate.

Type[] args

The types of arguments accepted by the object's constructor.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for Fluent syntax usage.

Exceptions
Type Condition
ClassNotInstantiableException

Thrown if the class is not instantiable, or if there is no constructor that accepts the specified arguments. It may also occur if one of the parameters is an object that does not have a parameterless constructor, in which case the exception will indicate the type that cannot be instantiated.

| Edit this page View Source

NewObject<T>(ILGenerator)

Inserts an object instantiation operation in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator NewObject<T>(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the object instantiation.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

The type of object to instantiate.

Exceptions
Type Condition
ClassNotInstantiableException

Thrown if the class is not instantiable, or if there is no constructor that accepts the specified arguments. This exception can also be thrown if one of the parameters is an object without a parameterless constructor, in which case the exception will indicate the type that cannot be instantiated.

| Edit this page View Source

NewObject<T>(ILGenerator, IEnumerable)

Inserts an object instantiation operation in the Microsoft® Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator NewObject<T>(this ILGenerator ilGen, IEnumerable args)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence in which to insert the object instantiation.

IEnumerable args

Arguments to pass to the object's constructor.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

The type of object to instantiate.

Exceptions
Type Condition
ClassNotInstantiableException

Thrown if the class is not instantiable, or if there is no constructor that accepts the specified arguments. This exception can also be thrown if one of the parameters is an object without a parameterless constructor, in which case the exception will indicate the type that cannot be instantiated.

| Edit this page View Source

Nop(ILGenerator)

Inserts a NOP instruction into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Nop(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

Pop(ILGenerator)

Inserts a pop operation that removes the value at the top of the stack into the Microsoft® Intermediate Language (MSIL) instruction stream.

Declaration
public static ILGenerator Pop(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

PutLabel(ILGenerator, Label)

Inserts a label into the MSIL instruction sequence at the current position.

Declaration
public static ILGenerator PutLabel(this ILGenerator ilGen, Label label)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence into which to insert the label.

Label label

Label to be inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling Fluent syntax.

| Edit this page View Source

RegisterConstantLoader(IConstantLoader)

Registers an IConstantLoader for the LoadConstant<T>(ILGenerator, T) method.

Declaration
public static void RegisterConstantLoader(IConstantLoader loader)
Parameters
Type Name Description
IConstantLoader loader

The IConstantLoader to register.

| Edit this page View Source

Remainder(ILGenerator)

Inserts a remainder operation into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Remainder(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

This method expects two values on the stack that can be used for a remainder calculation.

| Edit this page View Source

Return(ILGenerator)

Inserts the current method's return instruction into the MSIL instruction sequence.

Declaration
public static ILGenerator Return(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

Return(ILGenerator, Label)

Inserts the current method's return instruction into the MSIL instruction sequence, optionally marking an exit label.

Declaration
public static ILGenerator Return(this ILGenerator ilGen, Label exitLabel)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Label exitLabel

Previously created label that receives control from a branch to exit the executing method.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

SetField(ILGenerator, FieldInfo, Action<ILGenerator>)

Inserts the storage of a value into a field in the Microsoft Intermediate Language (MSIL) sequence, automatically determining whether a reference to this is required.

Declaration
public static ILGenerator SetField(this ILGenerator ilGen, FieldInfo field, Action<ILGenerator> value)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the field storage will be inserted.

FieldInfo field

The field into which to store the value.

Action<ILGenerator> value

Callback that loads the value to be stored in the field.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

This method automatically determines if a reference to this (Me in Visual Basic) is needed for non‑static fields; the instance load is omitted for static fields.

Net stack effect: -1

See Also
StoreField(ILGenerator, FieldInfo, Action<ILGenerator>)
| Edit this page View Source

SetField(ILGenerator, FieldInfo, Func<ILGenerator, ILGenerator>)

Inserts the storage of a value into a field in the Microsoft Intermediate Language (MSIL) instruction sequence, automatically determining whether a reference to this is required.

Declaration
public static ILGenerator SetField(this ILGenerator ilGen, FieldInfo field, Func<ILGenerator, ILGenerator> value)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence where the value storage will be inserted.

FieldInfo field

Field into which to store the value.

Func<ILGenerator, ILGenerator> value

Callback that will load the value to be stored in the field.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

This method automatically determines if a reference to this (Me in Visual Basic) is needed for non‑static fields; the instance load is omitted for static fields.

Net stack effect: -1

See Also
StoreField(ILGenerator, FieldInfo, Func<ILGenerator, ILGenerator>)
| Edit this page View Source

StoreDoubleElement(ILGenerator)

Inserts an operation that stores a double value into an array at the specified index in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreDoubleElement(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

Remarks

The operation requires that the stack contains the double value to be inserted at the top, and the int index immediately below it.

Net stack usage: -2

| Edit this page View Source

StoreElement(ILGenerator, int, byte)

Inserts an operation that stores a byte element in an array at the specified index onto the Microsoft® IL (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreElement(this ILGenerator ilGen, int index, byte element)
Parameters
Type Name Description
ILGenerator ilGen

Microsoft® IL (MSIL) instruction stream generator onto which to insert the operation.

int index

Index of the element in the array to be set.

byte element

Value to be set.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

StoreElement(ILGenerator, int, double)

Inserts an operation to store an element into an array at the specified index onto the Microsoft® IL (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreElement(this ILGenerator ilGen, int index, double element)
Parameters
Type Name Description
ILGenerator ilGen

Microsoft® IL (MSIL) instruction stream generator onto which to insert the operation.

int index

Index of the element in the array to be set.

double element

Value to be set.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for Fluent syntax.

| Edit this page View Source

StoreElement(ILGenerator, int, short)

Inserts an operation that stores a short element in an array at the specified index onto the Microsoft® IL (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreElement(this ILGenerator ilGen, int index, short element)
Parameters
Type Name Description
ILGenerator ilGen

Microsoft® IL (MSIL) instruction stream generator onto which to insert the operation.

int index

Index of the element in the array to be set.

short element

Value to be set.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

StoreElement(ILGenerator, int, int)

Inserts an operation that stores an int element in an array at the specified index onto the Microsoft® IL (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreElement(this ILGenerator ilGen, int index, int element)
Parameters
Type Name Description
ILGenerator ilGen

Microsoft® IL (MSIL) instruction stream generator onto which to insert the operation.

int index

Index of the element in the array to be set.

int element

Value to be set.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

StoreElement(ILGenerator, int, long)

Inserts an operation that stores a long element in an array at the specified index onto the Microsoft® IL (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreElement(this ILGenerator ilGen, int index, long element)
Parameters
Type Name Description
ILGenerator ilGen

Microsoft® IL (MSIL) instruction stream generator onto which to insert the operation.

int index

Index of the element in the array to be set.

long element

Value to be set.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

| Edit this page View Source

StoreElement(ILGenerator, int, object)

Inserts an operation to store an element into an array at the specified index onto the Microsoft® IL (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreElement(this ILGenerator ilGen, int index, object element)
Parameters
Type Name Description
ILGenerator ilGen

Microsoft® IL (MSIL) instruction stream generator onto which to insert the operation.

int index

Index of the element in the array to be set.

object element

Value to be set.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for Fluent syntax.

| Edit this page View Source

StoreElement(ILGenerator, int, float)

Inserts an operation to store an element into an array at the specified index onto the Microsoft® IL (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreElement(this ILGenerator ilGen, int index, float element)
Parameters
Type Name Description
ILGenerator ilGen

Microsoft® IL (MSIL) instruction stream generator onto which to insert the operation.

int index

Index of the element in the array to be set.

float element

Value to be set.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for Fluent syntax.

| Edit this page View Source

StoreField(ILGenerator, FieldInfo)

Inserts the storage of a value into a field in the MSIL instruction stream.

Declaration
public static ILGenerator StoreField(this ILGenerator ilGen, FieldInfo field)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator sequence where the value will be stored.

FieldInfo field

The field into which to store the value.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

Remarks

This method requires that the stack contain the value to store at the top, immediately followed by a reference to the instance if the field is an instance field. If the field is static, no reference to this (Me in Visual Basic) is required.

Net stack effect: -1

See Also
LoadArg0(ILGenerator)
StoreField(ILGenerator, FieldInfo, Action<ILGenerator>)
| Edit this page View Source

StoreField(ILGenerator, FieldInfo, Action<ILGenerator>)

Inserts the storage of a value into a field in the Microsoft Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreField(this ILGenerator ilGen, FieldInfo field, Action<ILGenerator> value)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence where the value will be stored.

FieldInfo field

Field into which to store the value.

Action<ILGenerator> value

Callback that will load the value to be stored in the field.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

This method does not automatically insert a reference to this (Me in Visual Basic) when the field is static; the caller must insert the instance load (LoadArg0(ILGenerator)).

Net stack effect: -1

See Also
SetField(ILGenerator, FieldInfo, Action<ILGenerator>)
| Edit this page View Source

StoreField(ILGenerator, FieldInfo, Func<ILGenerator, ILGenerator>)

Inserts the storage of a value into a field in the Microsoft Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreField(this ILGenerator ilGen, FieldInfo field, Func<ILGenerator, ILGenerator> value)
Parameters
Type Name Description
ILGenerator ilGen

Instruction sequence where the value will be stored.

FieldInfo field

Field into which to store the value.

Func<ILGenerator, ILGenerator> value

Callback that will load the value to be stored in the field.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

This method does not automatically determine whether a reference to this (Me in Visual Basic) is needed for static fields; the caller must insert the instance load (LoadArg0(ILGenerator)).

Net stack effect: -1

See Also
SetField(ILGenerator, FieldInfo, Func<ILGenerator, ILGenerator>)
| Edit this page View Source

StoreFloatElement(ILGenerator)

Inserts an operation that stores a float value into an array at the specified index in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreFloatElement(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

Remarks

The operation requires that the stack contains the float value to be inserted at the top, and the int index immediately below it.

Net stack usage: -2

| Edit this page View Source

StoreInt16Element(ILGenerator)

Inserts an operation that stores a short or ushort value into an array at the specified index in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreInt16Element(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

Remarks

The operation requires that the stack contains the short value to be inserted at the top, and the int index immediately below it.

Net stack usage: -2

| Edit this page View Source

StoreInt32Element(ILGenerator)

Inserts an operation that stores an int or uint value into an array at the specified index in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreInt32Element(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

Remarks

The operation requires that the stack contains the int value to be inserted at the top, and the int index immediately below it.

Net stack usage: -2

| Edit this page View Source

StoreInt64Element(ILGenerator)

Inserts an operation that stores a long or ulong value into an array at the specified index in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreInt64Element(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

Remarks

The operation requires that the stack contains the long value to be inserted at the top, and the int index immediately below it.

Net stack usage: -2

| Edit this page View Source

StoreInt8Element(ILGenerator)

Inserts an operation that stores a byte or sbyte value into an array at the specified index in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreInt8Element(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

Remarks

The operation requires that the stack contains the byte value to be inserted at the top, and the int index immediately below it.

Net stack usage: -2

| Edit this page View Source

StoreLocal(ILGenerator, LocalBuilder)

Inserts the storage of a value into a local variable in the MSIL instruction sequence.

Declaration
public static ILGenerator StoreLocal(this ILGenerator ilGen, LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance where the value will be stored.

LocalBuilder local

Local variable where the value will be stored.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

| Edit this page View Source

StoreNewLocal(ILGenerator, Type, out LocalBuilder)

Declares a new local variable of the specified type, stores a value into it, and returns the ILGenerator instance for fluent usage.

Declaration
public static ILGenerator StoreNewLocal(this ILGenerator ilGen, Type localType, out LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance where the value will be stored.

Type localType

Type of the local variable to declare.

LocalBuilder local

The newly declared local variable that will hold the value.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

| Edit this page View Source

StoreNewLocal<T>(ILGenerator, out LocalBuilder)

Declares a new local variable of type T, stores a value into it, and returns the ILGenerator instance for fluent usage.

Declaration
public static ILGenerator StoreNewLocal<T>(this ILGenerator ilGen, out LocalBuilder local)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance where the value will be stored.

LocalBuilder local

The newly declared local variable that will hold the value.

Returns
Type Description
ILGenerator

The same ILGenerator instance, enabling fluent syntax.

Type Parameters
Name Description
T

The type of the local variable to declare.

| Edit this page View Source

StoreProperty(ILGenerator, PropertyInfo)

Stores a value into a property in the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator StoreProperty(this ILGenerator ilGen, PropertyInfo prop)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the property storage will be inserted.

PropertyInfo prop

The property into which to store the value.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

This method requires the value to be stored to be on the top of the stack, immediately followed by a reference to the instance if the property is an instance property. If the property is static, no reference to this (Me in Visual Basic) is required.

Net stack effect: -1

See Also
LoadArg0(ILGenerator)
StoreProperty(ILGenerator, PropertyInfo, Action<ILGenerator>)
| Edit this page View Source

StoreProperty(ILGenerator, PropertyInfo, Action<ILGenerator>)

Inserts the storage of a value into a property in the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator StoreProperty(this ILGenerator ilGen, PropertyInfo prop, Action<ILGenerator> value)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the property storage will be inserted.

PropertyInfo prop

The property into which to store the value.

Action<ILGenerator> value

Callback that loads the value to be stored in the property.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

This method automatically determines if a reference to this (Me in Visual Basic) is required for non‑static properties; the instance load is omitted for static properties.

Net stack effect: -1

| Edit this page View Source

StoreProperty(ILGenerator, PropertyInfo, Func<ILGenerator, ILGenerator>)

Inserts the storage of a value into a property in the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator StoreProperty(this ILGenerator ilGen, PropertyInfo prop, Func<ILGenerator, ILGenerator> value)
Parameters
Type Name Description
ILGenerator ilGen

The ILGenerator instance to which the property storage will be inserted.

PropertyInfo prop

The property into which the value will be stored.

Func<ILGenerator, ILGenerator> value

Callback that loads the value to be stored in the property.

Returns
Type Description
ILGenerator

The same ILGenerator instance as ilGen, enabling fluent syntax.

Remarks

This method automatically determines whether a reference to this (Me in Visual Basic) must be added for instance properties; no reference is loaded for static properties.

Net stack effect: -1

| Edit this page View Source

StoreRefElement(ILGenerator)

Inserts an operation that stores a reference to an object into an array at the specified index in the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator StoreRefElement(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

Instruction stream into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, allowing for fluent syntax.

Remarks

The operation requires that the stack contains the object reference to be inserted at the top, and the int index immediately below it.

Net stack usage: -2

| Edit this page View Source

Subtract(ILGenerator)

Inserts a subtraction operation into the Microsoft® Intermediate Language (MSIL) instruction sequence.

Declaration
public static ILGenerator Subtract(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the operation is inserted.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Remarks

This method expects two values on the stack that can be subtracted.

| Edit this page View Source

Throw(ILGenerator)

Emits a throw instruction for an exception that is already instantiated on the stack into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator Throw(this ILGenerator ilGen)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the throw will be emitted.

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

| Edit this page View Source

Throw<T>(ILGenerator)

Emits code that creates and throws an exception with no arguments into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator Throw<T>(this ILGenerator ilGen) where T : Exception, new()
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the throw will be emitted.

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

Type Parameters
Name Description
T

The exception type to throw. Must have a public parameterless constructor.

| Edit this page View Source

TryCatch(ILGenerator, TryBlock, IEnumerable<KeyValuePair<Type, TryBlock>>)

Inserts a structured try/catch block into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator TryCatch(this ILGenerator ilGen, ILGeneratorExtensions.TryBlock tryBlock, IEnumerable<KeyValuePair<Type, ILGeneratorExtensions.TryBlock>> catchBlocks)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the try block will be inserted.

ILGeneratorExtensions.TryBlock tryBlock

Action that defines the instructions to emit in the try block. The action receives a label that may be used as the exit target via Leave(ILGenerator, Label).

IEnumerable<KeyValuePair<Type, ILGeneratorExtensions.TryBlock>> catchBlocks

Collection of catch blocks to insert. Each action receives a label that may be used as the exit target via Leave(ILGenerator, Label).

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

| Edit this page View Source

TryCatchFinally(ILGenerator, TryBlock, IEnumerable<KeyValuePair<Type, TryBlock>>, Action<ILGenerator>)

Inserts a structured try/catch /finally block into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator TryCatchFinally(this ILGenerator ilGen, ILGeneratorExtensions.TryBlock tryBlock, IEnumerable<KeyValuePair<Type, ILGeneratorExtensions.TryBlock>> catchBlocks, Action<ILGenerator> finallyBlock)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the try block will be inserted.

ILGeneratorExtensions.TryBlock tryBlock

Action that defines the instructions to emit in the try block. The action receives a label that may be used as the exit target via Leave(ILGenerator, Label).

IEnumerable<KeyValuePair<Type, ILGeneratorExtensions.TryBlock>> catchBlocks

Collection of catch blocks to insert. Each action receives a label that may be used as the exit target via Leave(ILGenerator, Label).

Action<ILGenerator> finallyBlock

Action that defines the instructions to emit in the finally block.

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

| Edit this page View Source

TryFinally(ILGenerator, TryBlock, FinallyBlock)

Inserts a structured try/finally block into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator TryFinally(this ILGenerator ilGen, ILGeneratorExtensions.TryBlock tryBlock, ILGeneratorExtensions.FinallyBlock finallyBlock)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the try block will be inserted.

ILGeneratorExtensions.TryBlock tryBlock

Action that defines the instructions to emit in the try block. The action receives a label that may be used as the exit target via Leave(ILGenerator, Label).

ILGeneratorExtensions.FinallyBlock finallyBlock

Action that defines the instructions to emit in the finally block.

Returns
Type Description
ILGenerator

The same ilGen instance, enabling fluent syntax.

| Edit this page View Source

Using(ILGenerator, LocalBuilder, UsingBlock)

Inserts a structured using block into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator Using(this ILGenerator ilGen, LocalBuilder disposable, ILGeneratorExtensions.UsingBlock usingBlock)
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the using block will be inserted.

LocalBuilder disposable

Reference to a LocalBuilder holding the disposable instance used within the using block.

ILGeneratorExtensions.UsingBlock usingBlock

Delegate that defines the actions to execute inside the using block.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

| Edit this page View Source

Using<T>(ILGenerator, UsingBlock)

Inserts a structured using block into the Microsoft Intermediate Language (MSIL) sequence.

Declaration
public static ILGenerator Using<T>(this ILGenerator ilGen, ILGeneratorExtensions.UsingBlock usingBlock) where T : IDisposable, new()
Parameters
Type Name Description
ILGenerator ilGen

The instruction sequence into which the using block will be inserted.

ILGeneratorExtensions.UsingBlock usingBlock

Delegate that defines the actions to execute inside the using block.

Returns
Type Description
ILGenerator

The same instance as ilGen, enabling fluent syntax.

Type Parameters
Name Description
T

Type of disposable object to instantiate for use within the using block.

  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX