internal static Delegate WrapAction(dynamic invokable, int length) { switch (length) { #region Optimizations case 0: return(new Action(() => invokable())); case 1: return(new Action <object>((a1) => invokable(a1))); case 2: return(new Action <object, object>((a1, a2) => invokable(a1, a2))); case 3: return(new Action <object, object, object>((a1, a2, a3) => invokable(a1, a2, a3))); case 4: return(new Action <object, object, object, object>((a1, a2, a3, a4) => invokable(a1, a2, a3, a4))); case 5: return(new Action <object, object, object, object, object>((a1, a2, a3, a4, a5) => invokable(a1, a2, a3, a4, a5))); case 6: return(new Action <object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6) => invokable(a1, a2, a3, a4, a5, a6))); case 7: return(new Action <object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7) => invokable(a1, a2, a3, a4, a5, a6, a7))); case 8: return(new Action <object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8) => invokable(a1, a2, a3, a4, a5, a6, a7, a8))); case 9: return(new Action <object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9))); case 10: return(new Action <object, object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10))); case 11: return(new Action <object, object, object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11))); case 12: return(new Action <object, object, object, object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12))); case 13: return(new Action <object, object, object, object, object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13))); case 14: return(new Action <object, object, object, object, object, object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14))); case 15: return(new Action <object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15))); case 16: return(new Action <object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object>((a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) => invokable(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16))); #endregion default: return(new DynamicAction(args => Impromptu.InvokeAction((object)invokable, args))); } }
/// <summary> /// Invokes the invocation on specified target with specific args. /// </summary> /// <param name="target"> The target. </param> /// <param name="args"> The args. </param> /// <returns> </returns> public virtual object Invoke(object target, params object[] args) { switch (Kind) { case InvocationKind.Constructor: return(Impromptu.InvokeConstructor((Type)target, args)); case InvocationKind.Convert: bool tExplict = false; if (Args.Length == 2) { tExplict = (bool)args[1]; } return(Impromptu.InvokeConvert(target, (Type)args[0], tExplict)); case InvocationKind.Get: return(Impromptu.InvokeGet(target, Name.Name)); case InvocationKind.Set: Impromptu.InvokeSet(target, Name.Name, args.FirstOrDefault()); return(null); case InvocationKind.GetIndex: return(Impromptu.InvokeGetIndex(target, args)); case InvocationKind.SetIndex: Impromptu.InvokeSetIndex(target, args); return(null); case InvocationKind.InvokeMember: return(Impromptu.InvokeMember(target, Name, args)); case InvocationKind.InvokeMemberAction: Impromptu.InvokeMemberAction(target, Name, args); return(null); case InvocationKind.InvokeMemberUnknown: { try { return(Impromptu.InvokeMember(target, Name, args)); } catch (RuntimeBinderException) { Impromptu.InvokeMemberAction(target, Name, args); return(null); } } case InvocationKind.Invoke: return(Impromptu.Invoke(target, args)); case InvocationKind.InvokeAction: Impromptu.InvokeAction(target, args); return(null); case InvocationKind.InvokeUnknown: { try { return(Impromptu.Invoke(target, args)); } catch (RuntimeBinderException) { Impromptu.InvokeAction(target, args); return(null); } } case InvocationKind.AddAssign: Impromptu.InvokeAddAssign(target, Name.Name, args.FirstOrDefault()); return(null); case InvocationKind.SubtractAssign: Impromptu.InvokeSubtractAssign(target, Name.Name, args.FirstOrDefault()); return(null); case InvocationKind.IsEvent: return(Impromptu.InvokeIsEvent(target, Name.Name)); default: throw new InvalidOperationException("Unknown Invocation Kind: " + Kind); } }