Show / Hide Table of Contents

Class CodeInstruction

An abstract wrapper around OpCode and their operands. Used by transpilers

Inheritance
System.Object
CodeInstruction
CodeMatch
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public class CodeInstruction

Constructors

| Improve this Doc View Source

CodeInstruction(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

| Improve this Doc View Source

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 Source

blocks

All exception block boundaries defined on this instruction

Declaration
public List<ExceptionBlock> blocks
Field Value
Type Description
System.Collections.Generic.List<ExceptionBlock>
| Improve this Doc View Source

labels

All labels defined on this instruction

Declaration
public List<Label> labels
Field Value
Type Description
System.Collections.Generic.List<System.Reflection.Emit.Label>
| Improve this Doc View Source

opcode

The opcode

Declaration
public OpCode opcode
Field Value
Type Description
System.Reflection.Emit.OpCode
| Improve this Doc View Source

operand

The operand

Declaration
public object operand
Field Value
Type Description
System.Object

Methods

| Improve this Doc View Source

Call(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
| Improve this Doc View Source

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
| Improve this Doc View Source

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 TypeFullName:MethodName, where the type name matches a form recognized by Type.GetType like Some.Namespace.Type.

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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
ArgumentIndex(CodeInstruction)
| Improve this Doc View Source

LoadField(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
| Improve this Doc View Source

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
LocalIndex(CodeInstruction)
| Improve this Doc View Source

StoreArgument(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
ArgumentIndex(CodeInstruction)
| Improve this Doc View Source

StoreField(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
| Improve this Doc View Source

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
LocalIndex(CodeInstruction)
| Improve this Doc View Source

ToString()

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

Overrides
System.Object.ToString()

Extension Methods

CodeInstructionExtensions.OperandIs(CodeInstruction, Object)
CodeInstructionExtensions.Is(CodeInstruction, OpCode, Object)
CodeInstructionExtensions.IsLdarg(CodeInstruction, Nullable<Int32>)
CodeInstructionExtensions.IsLdarga(CodeInstruction, Nullable<Int32>)
CodeInstructionExtensions.IsStarg(CodeInstruction, Nullable<Int32>)
CodeInstructionExtensions.IsLdloc(CodeInstruction, LocalBuilder)
CodeInstructionExtensions.IsStloc(CodeInstruction, LocalBuilder)
CodeInstructionExtensions.Branches(CodeInstruction, out Nullable<Label>)
CodeInstructionExtensions.Calls(CodeInstruction, MethodInfo)
CodeInstructionExtensions.LoadsConstant(CodeInstruction)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, Int64)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, Double)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, Enum)
CodeInstructionExtensions.LoadsConstant(CodeInstruction, String)
CodeInstructionExtensions.LoadsField(CodeInstruction, FieldInfo, Boolean)
CodeInstructionExtensions.StoresField(CodeInstruction, FieldInfo)
CodeInstructionExtensions.LocalIndex(CodeInstruction)
CodeInstructionExtensions.ArgumentIndex(CodeInstruction)
CodeInstructionExtensions.WithLabels(CodeInstruction, Label[])
CodeInstructionExtensions.WithLabels(CodeInstruction, IEnumerable<Label>)
CodeInstructionExtensions.ExtractLabels(CodeInstruction)
CodeInstructionExtensions.MoveLabelsTo(CodeInstruction, CodeInstruction)
CodeInstructionExtensions.MoveLabelsFrom(CodeInstruction, CodeInstruction)
CodeInstructionExtensions.WithBlocks(CodeInstruction, ExceptionBlock[])
CodeInstructionExtensions.WithBlocks(CodeInstruction, IEnumerable<ExceptionBlock>)
CodeInstructionExtensions.ExtractBlocks(CodeInstruction)
CodeInstructionExtensions.MoveBlocksTo(CodeInstruction, CodeInstruction)
CodeInstructionExtensions.MoveBlocksFrom(CodeInstruction, CodeInstruction)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX