Class CodeInstruction
An abstract wrapper around OpCode and their operands. Used by transpilers
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public class CodeInstruction
Constructors
| Improve this Doc View SourceCodeInstruction(CodeInstruction)
Create a full copy (including labels and exception blocks) of a CodeInstruction
Declaration
public CodeInstruction(CodeInstruction instruction)
Parameters
Type | Name | Description |
---|---|---|
CodeInstruction | instruction | The CodeInstruction to copy |
CodeInstruction(OpCode, Object)
Creates a new CodeInstruction with a given opcode and optional operand
Declaration
public CodeInstruction(OpCode opcode, object operand = null)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.Emit.OpCode | opcode | The opcode |
System.Object | operand | The operand |
Fields
| Improve this Doc View Sourceblocks
All exception block boundaries defined on this instruction
Declaration
public List<ExceptionBlock> blocks
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<ExceptionBlock> |
labels
All labels defined on this instruction
Declaration
public List<Label> labels
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<System.Reflection.Emit.Label> |
opcode
The opcode
Declaration
public OpCode opcode
Field Value
Type | Description |
---|---|
System.Reflection.Emit.OpCode |
operand
The operand
Declaration
public object operand
Field Value
Type | Description |
---|---|
System.Object |
Methods
| Improve this Doc View SourceCall(Expression<Action>)
Creates a CodeInstruction calling a method (CALL)
Declaration
public static CodeInstruction Call(Expression<Action> expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Action> | expression | The lambda expression using the method |
Returns
Type | Description |
---|---|
CodeInstruction |
Call(LambdaExpression)
Creates a CodeInstruction calling a method (CALL)
Declaration
public static CodeInstruction Call(LambdaExpression expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.LambdaExpression | expression | The lambda expression using the method |
Returns
Type | Description |
---|---|
CodeInstruction |
Call(String, Type[], Type[])
Creates a CodeInstruction calling a method (CALL)
Declaration
public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | typeColonMethodname | The target method in the form |
System.Type[] | parameters | Optional parameters to target a specific overload of the method |
System.Type[] | generics | Optional list of types that define the generic version of the method |
Returns
Type | Description |
---|---|
CodeInstruction | A code instruction that calls the method matching the arguments |
Call(Type, String, Type[], Type[])
Creates a CodeInstruction calling a method (CALL)
Declaration
public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The class/type where the method is declared |
System.String | name | The name of the method (case sensitive) |
System.Type[] | parameters | Optional parameters to target a specific overload of the method |
System.Type[] | generics | Optional list of types that define the generic version of the method |
Returns
Type | Description |
---|---|
CodeInstruction | A code instruction that calls the method matching the arguments |
Call<T>(Expression<Action<T>>)
Creates a CodeInstruction calling a method (CALL)
Declaration
public static CodeInstruction Call<T>(Expression<Action<T>> expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Action<T>> | expression | The lambda expression using the method |
Returns
Type | Description |
---|---|
CodeInstruction |
Type Parameters
Name | Description |
---|---|
T |
Call<T, TResult>(Expression<Func<T, TResult>>)
Creates a CodeInstruction calling a method (CALL)
Declaration
public static CodeInstruction Call<T, TResult>(Expression<Func<T, TResult>> expression)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<T, TResult>> | expression | The lambda expression using the method |
Returns
Type | Description |
---|---|
CodeInstruction |
Type Parameters
Name | Description |
---|---|
T | |
TResult |
CallClosure<T>(T)
Returns an instruction to call the specified closure
Declaration
public static CodeInstruction CallClosure<T>(T closure)
where T : Delegate
Parameters
Type | Name | Description |
---|---|---|
T | closure | The closure that defines the method to call |
Returns
Type | Description |
---|---|
CodeInstruction | A CodeInstruction that calls the closure as a method |
Type Parameters
Name | Description |
---|---|
T | The delegate type to emit |
Clone()
Clones a CodeInstruction and resets its labels and exception blocks
Declaration
public CodeInstruction Clone()
Returns
Type | Description |
---|---|
CodeInstruction | A lightweight copy of this code instruction |
Clone(Object)
Clones a CodeInstruction, resets labels and exception blocks and sets its operand
Declaration
public CodeInstruction Clone(object operand)
Parameters
Type | Name | Description |
---|---|---|
System.Object | operand | The operand |
Returns
Type | Description |
---|---|
CodeInstruction | A copy of this CodeInstruction with a new operand |
Clone(OpCode)
Clones a CodeInstruction, resets labels and exception blocks and sets its opcode
Declaration
public CodeInstruction Clone(OpCode opcode)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.Emit.OpCode | opcode | The opcode |
Returns
Type | Description |
---|---|
CodeInstruction | A copy of this CodeInstruction with a new opcode |
LoadArgument(Int32, Boolean)
Creates a CodeInstruction loading an argument with the given index, using the shorter forms when possible
Declaration
public static CodeInstruction LoadArgument(int index, bool useAddress = false)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the argument |
System.Boolean | useAddress | Use address of argument |
Returns
Type | Description |
---|---|
CodeInstruction |
See Also
| Improve this Doc View SourceLoadField(Type, String, Boolean)
Creates a CodeInstruction loading a field (LD[S]FLD[A])
Declaration
public static CodeInstruction LoadField(Type type, string name, bool useAddress = false)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The class/type where the field is defined |
System.String | name | The name of the field (case sensitive) |
System.Boolean | useAddress | Use address of field |
Returns
Type | Description |
---|---|
CodeInstruction |
LoadLocal(Int32, Boolean)
Creates a CodeInstruction loading a local with the given index, using the shorter forms when possible
Declaration
public static CodeInstruction LoadLocal(int index, bool useAddress = false)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index where the local is stored |
System.Boolean | useAddress | Use address of local |
Returns
Type | Description |
---|---|
CodeInstruction |
See Also
| Improve this Doc View SourceStoreArgument(Int32)
Creates a CodeInstruction storing to an argument with the given index, using the shorter forms when possible
Declaration
public static CodeInstruction StoreArgument(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the argument |
Returns
Type | Description |
---|---|
CodeInstruction |
See Also
| Improve this Doc View SourceStoreField(Type, String)
Creates a CodeInstruction storing to a field (ST[S]FLD)
Declaration
public static CodeInstruction StoreField(Type type, string name)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The class/type where the field is defined |
System.String | name | The name of the field (case sensitive) |
Returns
Type | Description |
---|---|
CodeInstruction |
StoreLocal(Int32)
Creates a CodeInstruction storing to a local with the given index, using the shorter forms when possible
Declaration
public static CodeInstruction StoreLocal(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index where the local is stored |
Returns
Type | Description |
---|---|
CodeInstruction |
See Also
| Improve this Doc View SourceToString()
Returns a string representation of the code instruction
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of the code instruction |