public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { var currying = _target as Currying; result = currying != null ? new Currying(currying.Target, currying.MemberName, currying.Args.Concat(TypeFactorization.MaybeRenameArguments(binder.CallInfo, args)).ToArray(), currying.TotalArgCount, currying.InvocationKind) : new Currying(_target, String.Empty, TypeFactorization.MaybeRenameArguments(binder.CallInfo, args), _totalArgCount); return(true); }
public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) { var tNamedArgs = TypeFactorization.MaybeRenameArguments(binder.CallInfo, args); var tNewArgs = _args.Concat(tNamedArgs).ToArray(); if (_totalArgCount.HasValue && (_totalArgCount - Args.Length - args.Length > 0)) //Not Done currying { result = new Currying(Target, MemberName, tNewArgs, TotalArgCount, InvocationKind); return(true); } var tInvokeDirect = String.IsNullOrWhiteSpace(_memberName); var tDel = _target as Delegate; if (tInvokeDirect && binder.CallInfo.ArgumentNames.Count == 0 && _target is Delegate) //Optimization for direct delegate calls { result = tDel.FastDynamicInvoke(tNewArgs); return(true); } Invocation tInvocation; if (binder.CallInfo.ArgumentNames.Count == 0) //If no argument names we can cache the callsite { InvocationCacheCompatible tCacheableInvocation; if (!invocation.TryGetValue(tNewArgs.Length, out tCacheableInvocation)) { tCacheableInvocation = new InvocationCacheCompatible(InvocationKind, _memberName, argCount: tNewArgs.Length, context: _target); invocation[tNewArgs.Length] = tCacheableInvocation; } tInvocation = tCacheableInvocation; } else { tInvocation = new Invocation(InvocationKind, _memberName); } result = tInvocation.Invoke(_target, tNewArgs); return(true); }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { result = new Currying(_target, binder.Name, TypeFactorization.MaybeRenameArguments(binder.CallInfo, args), _totalArgCount); return(true); }