Show / Hide Table of Contents

    Class ILContext

    An IL manipulation "context" with various helpers and direct access to the MethodBody.

    Inheritance
    System.Object
    ILContext
    Implements
    System.IDisposable
    Namespace: MonoMod.Cil
    Assembly: MonoMod.Utils.dll
    Syntax
    public class ILContext : Object, IDisposable

    Constructors

    ILContext(MethodDefinition)

    Declaration
    public ILContext(MethodDefinition method)
    Parameters
    Type Name Description
    Mono.Cecil.MethodDefinition method

    Fields

    ReferenceBag

    The current reference bag. Used for methods such as EmitReference and EmitDelegate.

    Declaration
    public IILReferenceBag ReferenceBag
    Field Value
    Type Description
    IILReferenceBag

    Properties

    Body

    The manipulated method body.

    Declaration
    public MethodBody Body { get; }
    Property Value
    Type Description
    Mono.Cecil.Cil.MethodBody

    IL

    The manipulated method's IL processor.

    Declaration
    public ILProcessor IL { get; }
    Property Value
    Type Description
    Mono.Cecil.Cil.ILProcessor

    Instrs

    The manipulated method instructions.

    Declaration
    public Collection<Instruction> Instrs { get; }
    Property Value
    Type Description
    Mono.Collections.Generic.Collection<Mono.Cecil.Cil.Instruction>

    IsReadOnly

    Has the context been made read-only? No further method access is possible, but the context has not yet been disposed.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    System.Boolean

    Labels

    A readonly list of all defined labels.

    Declaration
    public ReadOnlyCollection<ILLabel> Labels { get; }
    Property Value
    Type Description
    System.Collections.ObjectModel.ReadOnlyCollection<ILLabel>

    Method

    The manipulated method.

    Declaration
    public MethodDefinition Method { get; }
    Property Value
    Type Description
    Mono.Cecil.MethodDefinition

    Module

    The manipulated method's module.

    Declaration
    public ModuleDefinition Module { get; }
    Property Value
    Type Description
    Mono.Cecil.ModuleDefinition

    Methods

    AddReference<T>(T)

    Bind an arbitary object to an ILContext for static retrieval.

    Declaration
    public int AddReference<T>(T t)
    Parameters
    Type Name Description
    T t

    The object to store.

    Returns
    Type Description
    System.Int32

    The id to use in combination with the typeparam for object retrieval.

    Type Parameters
    Name Description
    T

    The type of the object. The combination of typeparam and id provides the unique static reference.

    At(Instruction)

    Declaration
    public ILCursor At(Instruction instr)
    Parameters
    Type Name Description
    Mono.Cecil.Cil.Instruction instr
    Returns
    Type Description
    ILCursor

    At(ILLabel)

    Declaration
    public ILCursor At(ILLabel label)
    Parameters
    Type Name Description
    ILLabel label
    Returns
    Type Description
    ILCursor

    At(Int32)

    Declaration
    public ILCursor At(int index)
    Parameters
    Type Name Description
    System.Int32 index
    Returns
    Type Description
    ILCursor

    DefineLabel()

    Define a new label to be marked with a cursor.

    Declaration
    public ILLabel DefineLabel()
    Returns
    Type Description
    ILLabel

    A label without a target instruction.

    DefineLabel(Instruction)

    Define a new label pointing at a given instruction.

    Declaration
    public ILLabel DefineLabel(Instruction target)
    Parameters
    Type Name Description
    Mono.Cecil.Cil.Instruction target

    The instruction the label will point at.

    Returns
    Type Description
    ILLabel

    A label pointing at the given instruction.

    Dispose()

    Dispose this context, making it read-only and invoking all OnDispose event listeners.

    Declaration
    public void Dispose()

    GetIncomingLabels(Instruction)

    Obtain all labels pointing at the given instruction.

    Declaration
    public IEnumerable<ILLabel> GetIncomingLabels(Instruction instr)
    Parameters
    Type Name Description
    Mono.Cecil.Cil.Instruction instr

    The instruction to get all labels for.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<ILLabel>

    All labels targeting the given instruction.

    Import(FieldInfo)

    See Mono.Cecil.ModuleDefinition.ImportReference(System.Reflection.FieldInfo)

    Declaration
    public FieldReference Import(FieldInfo field)
    Parameters
    Type Name Description
    System.Reflection.FieldInfo field
    Returns
    Type Description
    Mono.Cecil.FieldReference

    Import(MethodBase)

    See Mono.Cecil.ModuleDefinition.ImportReference(System.Reflection.MethodBase)

    Declaration
    public MethodReference Import(MethodBase method)
    Parameters
    Type Name Description
    System.Reflection.MethodBase method
    Returns
    Type Description
    Mono.Cecil.MethodReference

    Import(Type)

    See Mono.Cecil.ModuleDefinition.ImportReference(System.Type)

    Declaration
    public TypeReference Import(Type type)
    Parameters
    Type Name Description
    System.Type type
    Returns
    Type Description
    Mono.Cecil.TypeReference

    IndexOf(Instruction)

    Determine the index of a given instruction.

    Declaration
    public int IndexOf(Instruction instr)
    Parameters
    Type Name Description
    Mono.Cecil.Cil.Instruction instr

    The instruction to get the index of.

    Returns
    Type Description
    System.Int32

    The instruction index, or the end of the method body if it hasn't been found.

    Invoke(ILContext.Manipulator)

    Invoke a given manipulator callback.

    Declaration
    public void Invoke(ILContext.Manipulator manip)
    Parameters
    Type Name Description
    ILContext.Manipulator manip

    The manipulator to run in this context.

    MakeReadOnly()

    Mark this ILContext as read-only and prevent this context from further accessing the originally passed method.

    Declaration
    public void MakeReadOnly()
    Remarks

    If the method is altered prior to calling MakeReadOnly or afterwards by accessing the method directly, the results are undefined.

    ToString()

    Obtain a string representation of this context (method ID and body).

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String

    A string representation of this context.

    Events

    OnDispose

    Events which run when the context will be disposed.

    Declaration
    public event Action OnDispose
    Event Type
    Type Description
    System.Action

    Implements

    System.IDisposable
    Back to top Yet another C# modding swiss army knife.