Exemplo n.º 1
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            var        method           = (ESMethod)Value;
            Expression invokeExpression = null;
            var        numArgs          = args.Length;

            if (numArgs - method.NumArgs != 1)
            {
                var esClass = ValueClass;
                var kernel  = esClass.ObjectSpace;
                return(metaObjectToThrowInvalidFunctionCallException(
                           kernel.selectorToEvaluatMethodWithNumArgs(Math.Max(0, numArgs - 1)),
                           args,
                           "Argument count mismatch",
                           ESCompiledCode.methodFunctionTypeForNumArgs(method.NumArgs),
                           ESCompiledCode.blockFunctionTypeForNumArgs(args.Length)));
            }

            invokeExpression = ExpressionTreeGuru.expressionToInvokeESMethod(this.asExpressionWithFormalType(), expressionArrayFor(args));

            return(new DynamicMetaObject(invokeExpression, DefaultBindingRestrictions, method));
        }
Exemplo n.º 2
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            var        block            = (ESBlock)Value;
            Expression invokeExpression = null;
            var        numArgs          = args.Length;

            if (numArgs != block.NumArgs)
            {
                var esClass     = ValueClass;
                var objectSpace = esClass.ObjectSpace;
                return(metaObjectToThrowInvalidFunctionCallException(
                           objectSpace.selectorToEvaluatBlockWithNumArgs(numArgs),
                           args,
                           "Argument count mismatch",
                           ESCompiledCode.blockFunctionTypeForNumArgs(block.NumArgs),
                           ESCompiledCode.blockFunctionTypeForNumArgs(args.Length)));
            }

            invokeExpression = ExpressionTreeGuru.expressionToInvokeESBlock(this.asExpressionWithFormalType(), expressionArrayFor(args));

            return(new DynamicMetaObject(invokeExpression, DefaultBindingRestrictions, block));
        }