Skip to content

InstructionExtensions Class

Extension methods for Instruction.

C#
public static class InstructionExtensions

Inheritance object

Stores an instruction instance into an ‘out’ parameter variable while returning the same instruction instance for convenient use in methods that take instruction instances, e.g.

C#
weaver.InsertBeforeCurrent(
w.Create(OpCodes.Ldc_I4_0).Get(out var ldcI40),
w.Create(OpCodes.Ret).Get(out var ret)
);
C#
public static Instruction Get(this Instruction source, out Instruction instruction)

source Instruction
The instruction instance to get.

instruction Instruction
The got instruction instance.

Instruction
The same instruction instance.

Marks an instruction as a target of an MonoMod.Cil.ILLabel while returning the same instruction instance for convenient use in methods that take instruction instances, e.g.

C#
ILLabel label = weaver.DeclareLabel();
// ...
weaver.InsertBeforeCurrent(
w.Create(OpCodes.Ret).MarkLabel(label)
);
C#
public static Instruction MarkLabel(this Instruction instruction, ILLabel label)

instruction Instruction
The instruction to mark a label with.

label MonoMod.Cil.ILLabel
The label to be marked.

Instruction
The same instruction instance.

Creates and returns a clone of the provided instruction instance. Useful for reusing the same instruction in a method as inserting duplicate instruction instances into a method is problematic, such as breaking the target method compilation in certain cases.

C#
public static Instruction Clone(this Instruction instruction)

instruction Instruction
The instruction to clone.

Instruction
The clone.

Returns a string representation of an Instruction without fear of InvalidCastException.

C#
public static string ToStringSafe(this Instruction instruction)

instruction Instruction
Instruction to turn into a string representation.

string
String representation of an Instruction.