DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="2.1.0" />

 ManagedMethodPointer

Acts as modifier type for the parameter representing pointer to the managed method.
using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DotNext.Runtime.CompilerServices { public readonly struct ManagedMethodPointer : IEquatable<ManagedMethodPointer> { private readonly IntPtr methodPtr; internal ManagedMethodPointer(IntPtr methodPtr) { this.methodPtr = methodPtr; } internal ManagedMethodPointer(RuntimeMethodHandle method) { methodPtr = method.GetFunctionPointer(); } [System.Runtime.CompilerServices.NullableContext(1)] internal O Invoke<[System.Runtime.CompilerServices.Nullable(2)] I, [System.Runtime.CompilerServices.Nullable(2)] O>([In] [IsReadOnly] ref I arg0, int arg1) { return (O); } public bool Equals(ManagedMethodPointer other) { return methodPtr == other.methodPtr; } [System.Runtime.CompilerServices.NullableContext(2)] public override bool Equals(object other) { if (other is ManagedMethodPointer) { ManagedMethodPointer other2 = (ManagedMethodPointer)other; return Equals(other2); } return false; } public override int GetHashCode() { return methodPtr.GetHashCode(); } [System.Runtime.CompilerServices.NullableContext(1)] public override string ToString() { return methodPtr.ToString("X"); } public static bool operator ==(ManagedMethodPointer x, ManagedMethodPointer y) { return x.methodPtr == y.methodPtr; } public static bool operator !=(ManagedMethodPointer x, ManagedMethodPointer y) { return x.methodPtr != y.methodPtr; } } }