using System.Runtime.InteropServices; namespace Misaki.HighPerformance.LowLevel; public readonly struct FunctionPointer where T : Delegate { private readonly nint _ptr; private readonly T _delegate; /// /// Gets the native function pointer associated with this function pointer instance. /// public readonly nint Pointer => _ptr; /// /// Gets the delegate instance associated with the specified function pointer. /// /// This property uses to convert the function /// pointer to a delegate. Ensure that the function pointer is valid and compatible with the delegate type /// . public T Invoke => _delegate; /// /// Creates a new instance of this function pointer with the following native pointer. /// /// public FunctionPointer(nint ptr) { _ptr = ptr; _delegate = Marshal.GetDelegateForFunctionPointer(ptr); } }