/// <summary> /// Register a route: with a callback method and an object target /// </summary> /// <param name="method"></param> /// <param name="target"></param> internal Route(System.Reflection.MethodInfo method, object target) { Path = "/" + method.Name; Name = method.DeclaringType != null ? method.DeclaringType.Name + "." + method.Name : method.Name; _Reg = new System.Text.RegularExpressions.Regex("^(" + Path + "\\/?(\\?[^\\/]*)?)$", System.Text.RegularExpressions.RegexOptions.IgnoreCase); _Callback = method.CreateDelegate(target); }
/// <summary> /// Creates a delegate from a MethodInfo using <see cref="System.Linq.Expressions.Expression.GetDelegateType"/> /// </summary> /// <param name="method"></param> /// <returns></returns> public static System.Delegate CreateDelegate(System.Reflection.MethodInfo method) { if (method == null) { throw new System.ArgumentNullException("method"); } return(method.CreateDelegate(System.Linq.Expressions.Expression.GetDelegateType(method.GetParameters().Select(p => p.ParameterType).Concat(LinqExtensions.Yield(method.ReturnType)).ToArray()))); }
static public void HookR2API() { System.Type type = typeof(R2API.ItemDropAPI); System.Reflection.MethodInfo runOnBuildDropTable = type.GetMethod("RunOnBuildDropTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); On.RoR2.Run.BuildDropTable += (On.RoR2.Run.hook_BuildDropTable)runOnBuildDropTable.CreateDelegate(typeof(On.RoR2.Run.hook_BuildDropTable)); System.Reflection.MethodInfo addShrineStack = type.GetMethod("ShrineChanceBehaviorOnAddShrineStack", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static); IL.RoR2.ShrineChanceBehavior.AddShrineStack += addShrineStack.CreateDelegate(typeof(ILContext.Manipulator)) as ILContext.Manipulator; }
static Utf8CustomMarshaler() { System.Type t = typeof(System.Runtime.InteropServices.Marshal); System.Reflection.MethodInfo mi = t.GetMethod("SetLastWin32Error", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); // mi.Invoke(null, new object[] { (object)lastError }); s_setLastWin32Error = (System.Action<int>) mi.CreateDelegate(typeof(System.Action<int>)); s_staticInstance = new Utf8CustomMarshaler(); }
public Action GetSerializedEventDelegate(int eventIndex) { UnityEngine.Object target = serializedEvent.GetPersistentTarget(eventIndex); System.Reflection.MethodInfo targetMethod = target.GetType().GetMethod(serializedEvent.GetPersistentMethodName(eventIndex)); #if NET_4_6 return(targetMethod.CreateDelegate(typeof(Action), target) as Action); #else return(Delegate.CreateDelegate(typeof(Action), target, serializedEvent.GetPersistentMethodName(eventIndex)) as Action); #endif }
static int _m_CreateDelegate(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); System.Reflection.MethodInfo gen_to_be_invoked = (System.Reflection.MethodInfo)translator.FastGetCSObj(L, 1); int gen_param_count = LuaAPI.lua_gettop(L); if (gen_param_count == 2 && translator.Assignable <System.Type>(L, 2)) { System.Type _delegateType = (System.Type)translator.GetObject(L, 2, typeof(System.Type)); System.Delegate gen_ret = gen_to_be_invoked.CreateDelegate(_delegateType); translator.Push(L, gen_ret); return(1); } if (gen_param_count == 3 && translator.Assignable <System.Type>(L, 2) && translator.Assignable <object>(L, 3)) { System.Type _delegateType = (System.Type)translator.GetObject(L, 2, typeof(System.Type)); object _target = translator.GetObject(L, 3, typeof(object)); System.Delegate gen_ret = gen_to_be_invoked.CreateDelegate(_delegateType, _target); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } return(LuaAPI.luaL_error(L, "invalid arguments to System.Reflection.MethodInfo.CreateDelegate!")); }