Show / Hide Table of Contents

Class MethodInvoker

A helper class to invoke method with delegates

Inheritance
object
MethodInvoker
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public static class MethodInvoker

Methods

GetHandler(MethodInfo, bool)

Creates a fast invocation handler from a method

Declaration
public static FastInvokeHandler GetHandler(MethodInfo methodInfo, bool directBoxValueAccess = false)
Parameters
Type Name Description
MethodInfo methodInfo

The method to invoke

bool directBoxValueAccess

Controls if boxed value object is accessed/updated directly

Returns
Type Description
FastInvokeHandler

The FastInvokeHandler

Remarks

The directBoxValueAccess option controls how value types passed by reference (e.g. ref int, out my_struct) are handled in the arguments array passed to the fast invocation handler. Since the arguments array is an object array, any value types contained within it are actually references to a boxed value object. Like any other object, there can be other references to such boxed value objects, other than the reference within the arguments array.

For example,

var val = 5;
var box = (object)val;
var arr = new object[] { box };
handler(arr); // for a method with parameter signature: ref/out/in int
            <p>
        If <code>directBoxValueAccess</code> is <code>true</code>, the boxed value object is accessed (and potentially updated) directly when the handler is called,
        such that all references to the boxed object reflect the potentially updated value.
        In the above example, if the method associated with the handler updates the passed (boxed) value to 10, both <code>box</code> and <code>arr[0]</code>
        now reflect the value 10. Note that the original <code>val</code> is not updated, since boxing always copies the value into the new boxed value object.
        </p>
            <p>
        If <code>directBoxValueAccess</code> is <code>false</code> (default), the boxed value object in the arguments array is replaced with a "reboxed" value object,
        such that potential updates to the value are reflected only in the arguments array.
        In the above example, if the method associated with the handler updates the passed (boxed) value to 10, only <code>arr[0]</code> now reflects the value 10.
        </p>
In this article
Back to top Generated by DocFX