public void Run(ExecutionContextLightup executionContext, Action<object> callback, object state) { if (LightupType.ExecutionContext == null || LightupType.ContextCallback == null) throw new PlatformNotSupportedException(); // Replace the Action<object> with a ContextCallback Delegate contextCallback = LightupServices.ReplaceWith(callback, LightupType.ContextCallback); Type actionRepresentingSignature = typeof(Action<,,>).MakeGenericType(LightupType.ExecutionContext, LightupType.ContextCallback, typeof(object)); Delegate d = GetMethodAccessor(ref _run, actionRepresentingSignature, "Run"); d.DynamicInvoke(executionContext._executionContext, contextCallback, state); }
public static Type[] GetMethodArgumentTypes(Type actionOrFuncType, bool bindInstance = true) { Type[] array = actionOrFuncType.GetGenericArguments(); if (!bindInstance) { array = Enumerable.ToArray <Type>(Enumerable.Skip <Type>(array, 1)); } if (LightupServices.IsActionType(actionOrFuncType)) { return(array); } return(Enumerable.ToArray <Type>(Enumerable.Take <Type>(array, array.Length - 1))); }
private Delegate CreateMethodAccessor(Type type, string name, bool bindInstance = true) { if (_type == null) { return(null); } Type[] methodArgumentTypes = LightupServices.GetMethodArgumentTypes(type, bindInstance); MethodInfo method = _type.GetMethod(name, methodArgumentTypes); if (method == null) { return(null); } return(LightupServices.CreateDelegate(type, bindInstance ? GetInstance() : null, method)); }
public static ThreadLightup Create(Action <object> start) { Type delegateType = LightupType.ParameterizedThreadStart; if (delegateType == null) { throw new InvalidOperationException(); } // Replace the Action<object> with a ParameterizedThreadStart Delegate parameterizedThreadStart = LightupServices.ReplaceWith(start, delegateType); Thread thread = Create <Thread>(parameterizedThreadStart); return(new ThreadLightup(thread)); }
public void Run(ExecutionContextLightup executionContext, Action <object> callback, object state) { if (LightupType.ExecutionContext == null || LightupType.ContextCallback == null) { throw new PlatformNotSupportedException(); } Delegate dlg = LightupServices.ReplaceWith(callback, LightupType.ContextCallback); Type type = typeof(Action <, ,>).MakeGenericType(new Type[] { LightupType.ExecutionContext, LightupType.ContextCallback, typeof(object) }); Delegate methodAccessor = base.GetMethodAccessor(ref _run, type, "Run", true); methodAccessor.DynamicInvoke(new object[] { executionContext._executionContext, dlg, state }); }