Class CodeInstructionExtensions
- Namespace
- HarmonyLib
- Assembly
- 0Harmony.dll
Extensions for CodeInstruction
public static class CodeInstructionExtensions
- Inheritance
-
objectCodeInstructionExtensions
Methods
ArgumentIndex(CodeInstruction)
Returns the index targeted by this ldarg, ldarga, or starg
public static int ArgumentIndex(this CodeInstruction code)
Parameters
codeCodeInstructionThe CodeInstruction
Returns
- int
The index it targets
- See Also
-
StoreArgument(int)
Branches(CodeInstruction, out Label?)
Tests if the code instruction branches
public static bool Branches(this CodeInstruction code, out Label? label)
Parameters
codeCodeInstructionThe CodeInstruction
labelLabel?The label if the instruction is a branch operation or null if not
Returns
- bool
True if the instruction branches
Calls(CodeInstruction, MethodInfo)
Tests if the code instruction calls the method
public static bool Calls(this CodeInstruction code, MethodInfo method)
Parameters
codeCodeInstructionThe CodeInstruction
methodMethodInfoThe method
Returns
- bool
True if the instruction calls the method
ExtractBlocks(CodeInstruction)
Extracts all ExceptionBlocks from the code instruction and returns them
public static List<ExceptionBlock> ExtractBlocks(this CodeInstruction code)
Parameters
codeCodeInstructionThe CodeInstruction
Returns
- List<ExceptionBlock>
A list of ExceptionBlock
ExtractLabels(CodeInstruction)
Extracts all labels from the code instruction and returns them
public static List<Label> ExtractLabels(this CodeInstruction code)
Parameters
codeCodeInstructionThe CodeInstruction
Returns
- List<Label>
A list of System.Reflection.Emit.Label
Is(CodeInstruction, OpCode, object)
Shortcut for
code.opcode == opcode && code.OperandIs(operand)
public static bool Is(this CodeInstruction code, OpCode opcode, object operand)
Parameters
codeCodeInstructionThe CodeInstruction
opcodeOpCodeThe System.Reflection.Emit.OpCode
operandobjectThe operand value
Returns
- bool
True if the opcode is equal to the given opcode and the operand has the same type and is equal to the given operand
IsLdarg(CodeInstruction, int?)
Tests for any form of Ldarg*
public static bool IsLdarg(this CodeInstruction code, int? n = null)
Parameters
codeCodeInstructionThe CodeInstruction
nint?The (optional) index
Returns
- bool
True if it matches one of the variations
IsLdarga(CodeInstruction, int?)
Tests for Ldarga/Ldarga_S
public static bool IsLdarga(this CodeInstruction code, int? n = null)
Parameters
codeCodeInstructionThe CodeInstruction
nint?The (optional) index
Returns
- bool
True if it matches one of the variations
IsLdloc(CodeInstruction, LocalBuilder)
Tests for any form of Ldloc*
public static bool IsLdloc(this CodeInstruction code, LocalBuilder variable = null)
Parameters
codeCodeInstructionThe CodeInstruction
variableLocalBuilderThe optional local variable
Returns
- bool
True if it matches one of the variations
IsStarg(CodeInstruction, int?)
Tests for Starg/Starg_S
public static bool IsStarg(this CodeInstruction code, int? n = null)
Parameters
codeCodeInstructionThe CodeInstruction
nint?The (optional) index
Returns
- bool
True if it matches one of the variations
IsStloc(CodeInstruction, LocalBuilder)
Tests for any form of Stloc*
public static bool IsStloc(this CodeInstruction code, LocalBuilder variable = null)
Parameters
codeCodeInstructionThe CodeInstruction
variableLocalBuilderThe optional local variable
Returns
- bool
True if it matches one of the variations
IsValid(OpCode)
Returns if an System.Reflection.Emit.OpCode is initialized and valid
public static bool IsValid(this OpCode code)
Parameters
codeOpCodeThe System.Reflection.Emit.OpCode
Returns
- bool
LoadsConstant(CodeInstruction)
Tests if the code instruction loads a constant
public static bool LoadsConstant(this CodeInstruction code)
Parameters
codeCodeInstructionThe CodeInstruction
Returns
- bool
True if the instruction loads a constant
LoadsConstant(CodeInstruction, double)
Tests if the code instruction loads a floating point constant
public static bool LoadsConstant(this CodeInstruction code, double number)
Parameters
codeCodeInstructionThe CodeInstruction
numberdoubleThe floating point constant
Returns
- bool
True if the instruction loads the constant
LoadsConstant(CodeInstruction, Enum)
Tests if the code instruction loads an enum constant
public static bool LoadsConstant(this CodeInstruction code, Enum e)
Parameters
codeCodeInstructionThe CodeInstruction
eEnumThe enum
Returns
- bool
True if the instruction loads the constant
LoadsConstant(CodeInstruction, long)
Tests if the code instruction loads an integer constant
public static bool LoadsConstant(this CodeInstruction code, long number)
Parameters
codeCodeInstructionThe CodeInstruction
numberlongThe integer constant
Returns
- bool
True if the instruction loads the constant
LoadsConstant(CodeInstruction, string)
Tests if the code instruction loads a string constant
public static bool LoadsConstant(this CodeInstruction code, string str)
Parameters
codeCodeInstructionThe CodeInstruction
strstringThe string
Returns
- bool
True if the instruction loads the constant
LoadsField(CodeInstruction, FieldInfo, bool)
Tests if the code instruction loads a field
public static bool LoadsField(this CodeInstruction code, FieldInfo field, bool byAddress = false)
Parameters
codeCodeInstructionThe CodeInstruction
fieldFieldInfoThe field
byAddressboolSet to true if the address of the field is loaded
Returns
- bool
True if the instruction loads the field
LocalIndex(CodeInstruction)
Returns the index targeted by this ldloc, ldloca, or stloc
public static int LocalIndex(this CodeInstruction code)
Parameters
codeCodeInstructionThe CodeInstruction
Returns
- int
The index it targets
- See Also
-
StoreLocal(int)
MoveBlocksFrom(CodeInstruction, CodeInstruction)
Moves all ExceptionBlocks from another code instruction to the current one
public static CodeInstruction MoveBlocksFrom(this CodeInstruction code, CodeInstruction other)
Parameters
codeCodeInstructionThe CodeInstruction to move the ExceptionBlocks to
otherCodeInstructionThe other CodeInstruction to move the ExceptionBlocks from
Returns
- CodeInstruction
The code instruction that received the blocks
MoveBlocksTo(CodeInstruction, CodeInstruction)
Moves all ExceptionBlocks from the code instruction to another one
public static CodeInstruction MoveBlocksTo(this CodeInstruction code, CodeInstruction other)
Parameters
codeCodeInstructionThe CodeInstruction to move the ExceptionBlocks from
otherCodeInstructionThe other CodeInstruction to move the ExceptionBlocks to
Returns
- CodeInstruction
The code instruction blocks were moved from (now empty)
MoveLabelsFrom(CodeInstruction, CodeInstruction)
Moves all labels from another code instruction to the current one
public static CodeInstruction MoveLabelsFrom(this CodeInstruction code, CodeInstruction other)
Parameters
codeCodeInstructionThe CodeInstruction to move the labels to
otherCodeInstructionThe other CodeInstruction to move the labels from
Returns
- CodeInstruction
The code instruction that received the labels
MoveLabelsTo(CodeInstruction, CodeInstruction)
Moves all labels from the code instruction to another one
public static CodeInstruction MoveLabelsTo(this CodeInstruction code, CodeInstruction other)
Parameters
codeCodeInstructionThe CodeInstruction to move the labels from
otherCodeInstructionThe other CodeInstruction to move the labels to
Returns
- CodeInstruction
The code instruction labels were moved from (now empty)
OperandIs(CodeInstruction, object)
Shortcut for testing whether the operand is equal to a non-null value
public static bool OperandIs(this CodeInstruction code, object value)
Parameters
codeCodeInstructionThe CodeInstruction
valueobjectThe value
Returns
- bool
True if the operand has the same type and is equal to the value
StoresField(CodeInstruction, FieldInfo)
Tests if the code instruction stores a field
public static bool StoresField(this CodeInstruction code, FieldInfo field)
Parameters
codeCodeInstructionThe CodeInstruction
fieldFieldInfoThe field
Returns
- bool
True if the instruction stores this field
WithBlocks(CodeInstruction, params ExceptionBlock[])
Adds ExceptionBlocks to the code instruction and return it
public static CodeInstruction WithBlocks(this CodeInstruction code, params ExceptionBlock[] blocks)
Parameters
codeCodeInstructionThe CodeInstruction
blocksExceptionBlock[]One or several ExceptionBlock to add
Returns
- CodeInstruction
The same code instruction
WithBlocks(CodeInstruction, IEnumerable<ExceptionBlock>)
Adds ExceptionBlocks to the code instruction and return it
public static CodeInstruction WithBlocks(this CodeInstruction code, IEnumerable<ExceptionBlock> blocks)
Parameters
codeCodeInstructionThe CodeInstruction
blocksIEnumerable<ExceptionBlock>An enumeration of ExceptionBlock
Returns
- CodeInstruction
The same code instruction
WithLabels(CodeInstruction, IEnumerable<Label>)
Adds labels to the code instruction and return it
public static CodeInstruction WithLabels(this CodeInstruction code, IEnumerable<Label> labels)
Parameters
codeCodeInstructionThe CodeInstruction
labelsIEnumerable<Label>An enumeration of System.Reflection.Emit.Label
Returns
- CodeInstruction
The same code instruction
WithLabels(CodeInstruction, params Label[])
Adds labels to the code instruction and return it
public static CodeInstruction WithLabels(this CodeInstruction code, params Label[] labels)
Parameters
codeCodeInstructionThe CodeInstruction
labelsLabel[]One or several System.Reflection.Emit.Label to add
Returns
- CodeInstruction
The same code instruction