/// <summary> /// Creates a CallbackFunction from a MethodInfo relative to a function. /// </summary> /// <param name="mi">The MethodInfo object.</param> /// <param name="obj">The object to which the function applies, or null for static methods.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">The method is not static.</exception> public static CallbackFunction FromMethodInfo(System.Reflection.MethodBase mi, IntPtr dataTypePtr, object obj = null) { MethodMemberDescriptor descr = new MethodMemberDescriptor(mi); descr.DataTypePtr = dataTypePtr; return(descr.GetCallbackFunction().SetCallbackTarget(obj)); }
/// <summary> /// Creates a CallbackFunction from a delegate. /// </summary> /// <param name="script">The script.</param> /// <param name="del">The delegate.</param> /// <param name="accessMode">The access mode.</param> /// <returns></returns> public static CallbackFunction FromDelegate(Delegate del, IntPtr dataTypePtr) { #if NETFX_CORE MethodMemberDescriptor descr = new MethodMemberDescriptor(del.GetMethodInfo()); #else MethodMemberDescriptor descr = new MethodMemberDescriptor(del.Method); descr.DataTypePtr = dataTypePtr; #endif return(descr.GetCallbackFunction().SetCallbackTarget(del.Target)); }