This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_BURST_FEATURE_FUNCPTR | |
using System; | |
using System.Collections.Generic; | |
using System.Reflection; | |
using System.Reflection.Emit; | |
using System.Runtime.InteropServices; | |
using Unity.Burst; | |
namespace BurstHelper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static partial class Util | |
{ | |
const string kDelegateInvokeMethodName = "Invoke"; | |
// http://www.codeproject.com/Tips/441743/A-look-at-marshalling-delegates-in-NET | |
public static T GetDelegateForFunctionPointer<T>(IntPtr ptr, System.Runtime.InteropServices.CallingConvention call_conv) | |
where T : class | |
{ | |
Contract.Requires<ArgumentException>(typeof(T).IsSubclassOf(typeof(Delegate))); | |
Contract.Requires<ArgumentNullException>(ptr != IntPtr.Zero); | |
Contract.Requires<ArgumentException>(call_conv != System.Runtime.InteropServices.CallingConvention.ThisCall, |