Class MethodInvoker
A helper class to invoke method with delegates
Inheritance
Namespace: HarmonyLib
Assembly: 0Harmony.dll
Syntax
public static class MethodInvoker
Methods
| Improve this Doc View SourceGetHandler(MethodInfo, Boolean)
Creates a fast invocation handler from a method
Declaration
public static FastInvokeHandler GetHandler(MethodInfo methodInfo, bool directBoxValueAccess = false)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.MethodInfo | methodInfo | The method to invoke |
System.Boolean | directBoxValueAccess | Controls if boxed value object is accessed/updated directly |
Returns
Type | Description |
---|---|
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.
var val = 5;
var box = (object)val;
var arr = new object[] { box };
handler(arr); // for a method with parameter signature: ref/out/in int
If directBoxValueAccess
is true
, 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 box
and arr[0]
now reflect the value 10. Note that the original val
is not updated, since boxing always copies the value into the new boxed value object.
If directBoxValueAccess
is false
(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 arr[0]
now reflects the value 10.