Class CodeInstruction
- Namespace
- HarmonyLib
- Assembly
- 0Harmony.dll
An abstract wrapper around OpCode and their operands. Used by transpilers
public class CodeInstruction
- Inheritance
-
objectCodeInstruction
- Derived
- Extension Methods
Constructors
CodeInstruction(CodeInstruction)
Create a full copy (including labels and exception blocks) of a CodeInstruction
public CodeInstruction(CodeInstruction instruction)
Parameters
instructionCodeInstructionThe CodeInstruction to copy
CodeInstruction(OpCode, object)
Creates a new CodeInstruction with a given opcode and optional operand
public CodeInstruction(OpCode opcode, object operand = null)
Parameters
opcodeOpCodeThe opcode
operandobjectThe operand
Fields
blocks
All exception block boundaries defined on this instruction
public List<ExceptionBlock> blocks
Field Value
- List<ExceptionBlock>
labels
All labels defined on this instruction
public List<Label> labels
Field Value
- List<Label>
opcode
The opcode
public OpCode opcode
Field Value
- OpCode
operand
The operand
public object operand
Field Value
- object
Methods
Call(Expression<Action>)
Creates a CodeInstruction calling a method (CALL)
public static CodeInstruction Call(Expression<Action> expression)
Parameters
expressionExpression<Action>The lambda expression using the method
Returns
- CodeInstruction
A new Codeinstruction
Call(LambdaExpression)
Creates a CodeInstruction calling a method (CALL)
public static CodeInstruction Call(LambdaExpression expression)
Parameters
expressionLambdaExpressionThe lambda expression using the method
Returns
- CodeInstruction
A new Codeinstruction
Call(string, Type[], Type[])
Creates a CodeInstruction calling a method (CALL)
public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null)
Parameters
typeColonMethodnamestringThe target method in the form
TypeFullName:MethodName, where the type name matches a form recognized by Type.GetType likeSome.Namespace.Type.parametersType[]Optional parameters to target a specific overload of the method
genericsType[]Optional list of types that define the generic version of the method
Returns
- CodeInstruction
A code instruction that calls the method matching the arguments
Call(Type, string, Type[], Type[])
Creates a CodeInstruction calling a method (CALL)
public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null)
Parameters
typeTypeThe class/type where the method is declared
namestringThe name of the method (case sensitive)
parametersType[]Optional parameters to target a specific overload of the method
genericsType[]Optional list of types that define the generic version of the method
Returns
- CodeInstruction
A code instruction that calls the method matching the arguments
CallClosure<T>(T)
Returns an instruction to call the specified closure
public static CodeInstruction CallClosure<T>(T closure) where T : Delegate
Parameters
closureTThe closure that defines the method to call
Returns
- CodeInstruction
A CodeInstruction that calls the closure as a method
Type Parameters
TThe delegate type to emit
Call<T>(Expression<Action<T>>)
Creates a CodeInstruction calling a method (CALL)
public static CodeInstruction Call<T>(Expression<Action<T>> expression)
Parameters
expressionExpression<Action<T>>The lambda expression using the method
Returns
- CodeInstruction
A new Codeinstruction
Type Parameters
T
Call<T, TResult>(Expression<Func<T, TResult>>)
Creates a CodeInstruction calling a method (CALL)
public static CodeInstruction Call<T, TResult>(Expression<Func<T, TResult>> expression)
Parameters
expressionExpression<Func<T, TResult>>The lambda expression using the method
Returns
- CodeInstruction
A new Codeinstruction
Type Parameters
TTResult
Clone()
Clones a CodeInstruction and resets its labels and exception blocks
public CodeInstruction Clone()
Returns
- CodeInstruction
A lightweight copy of this code instruction
Clone(object)
Clones a CodeInstruction, resets labels and exception blocks and sets its operand
public CodeInstruction Clone(object operand)
Parameters
operandobjectThe operand
Returns
- CodeInstruction
A copy of this CodeInstruction with a new operand
Clone(OpCode)
Clones a CodeInstruction, resets labels and exception blocks and sets its opcode
public CodeInstruction Clone(OpCode opcode)
Parameters
opcodeOpCodeThe opcode
Returns
- CodeInstruction
A copy of this CodeInstruction with a new opcode
HasBlock(ExceptionBlockType)
Checks if a CodeInstruction contains a given exception block type
public bool HasBlock(ExceptionBlockType type)
Parameters
typeExceptionBlockTypeType of the exception block to check for
Returns
- bool
True if the instruction contains the exception block type, false otherwise
LoadArgument(int, bool)
Creates a CodeInstruction loading an argument with the given index, using the shorter forms when possible
public static CodeInstruction LoadArgument(int index, bool useAddress = false)
Parameters
indexintThe index of the argument
useAddressboolUse address of argument
Returns
- CodeInstruction
A new Codeinstruction
- See Also
LoadField(Type, string, bool)
Creates a CodeInstruction loading a field (LD[S]FLD[A])
public static CodeInstruction LoadField(Type type, string name, bool useAddress = false)
Parameters
typeTypeThe class/type where the field is defined
namestringThe name of the field (case sensitive)
useAddressboolUse address of field
Returns
- CodeInstruction
A new Codeinstruction
LoadLocal(int, bool)
Creates a CodeInstruction loading a local with the given index, using the shorter forms when possible
public static CodeInstruction LoadLocal(int index, bool useAddress = false)
Parameters
indexintThe index where the local is stored
useAddressboolUse address of local
Returns
- CodeInstruction
A new Codeinstruction
- See Also
StoreArgument(int)
Creates a CodeInstruction storing to an argument with the given index, using the shorter forms when possible
public static CodeInstruction StoreArgument(int index)
Parameters
indexintThe index of the argument
Returns
- CodeInstruction
A new Codeinstruction
- See Also
StoreField(Type, string)
Creates a CodeInstruction storing to a field (ST[S]FLD)
public static CodeInstruction StoreField(Type type, string name)
Parameters
typeTypeThe class/type where the field is defined
namestringThe name of the field (case sensitive)
Returns
- CodeInstruction
A new Codeinstruction
StoreLocal(int)
Creates a CodeInstruction storing to a local with the given index, using the shorter forms when possible
public static CodeInstruction StoreLocal(int index)
Parameters
indexintThe index where the local is stored
Returns
- CodeInstruction
A new Codeinstruction
- See Also
ToString()
Returns a string representation of the code instruction
public override string ToString()
Returns
- string
A string representation of the code instruction