Ejemplo n.º 1
0
        public Expression GetFunctionExpression(string funcname, Expression argexp, Expression argParams, ParameterExpression inputParams, Expression inputContextParam, List <InputVar> compiledInputVarsList)
        {
            switch (funcname)
            {
            case "f:substring":
                if (argexp is NewArrayExpression)
                {
                    if ((argexp as NewArrayExpression).Expressions.Count > 2)
                    {
                        return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Substring",
                                                                                                          new[] { typeof(string), typeof(int), typeof(int) }),
                                               ExFuncs.GetArgAsString(ExFuncs.GetArgIndex(argexp, 0)),
                                               ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 1)),
                                               ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 2))));
                    }
                    return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Substring",
                                                                                                      new[] { typeof(string), typeof(int) }),
                                           ExFuncs.GetArgAsString(ExFuncs.GetArgIndex(argexp, 0)),
                                           ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 1))));
                }
                // otherwise we need to inspect the number of args at runtime
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("SubstringRuntime",
                                                                                                  new[] { typeof(object[]) }),
                                       ExCasts.WrapArguments(argexp)));

            case "f:length":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Length",
                                                                                                  new[] { typeof(string) }),
                                       ExFuncs.GetArgAsString(ExFuncs.GetArgIndex(argexp, 0))));

            case "f:comma":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Comma",
                                                                                                  new[] { typeof(string[]) }),
                                       Expression.Call(typeof(ExCasts).GetTypeInfo().GetDeclaredMethod("UnwrapStringArray"),
                                                       ExCasts.WrapArguments(argexp))));

            case "f:commaand":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("CommaAnd",
                                                                                                  new[] { typeof(string[]) }),
                                       Expression.Call(typeof(ExCasts).GetTypeInfo().GetDeclaredMethod("UnwrapStringArray"),
                                                       ExCasts.WrapArguments(argexp))));

            case "f:replace":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Replace",
                                                                                                  new[] { typeof(string), typeof(string), typeof(string) }),
                                       ExFuncs.GetArgAsString(ExFuncs.GetArgIndex(argexp, 0)),
                                       ExFuncs.GetArgAsString(ExFuncs.GetArgIndex(argexp, 1)),
                                       ExFuncs.GetArgAsString(ExFuncs.GetArgIndex(argexp, 2))));

            default:
                throw new Exception("Func '" + funcname + "' not found in library '" + GetLibraryName() + "'");
            }
        }
Ejemplo n.º 2
0
        public Expression GetFunctionExpression(string funcname, Expression argexp, Expression argParams, ParameterExpression inputParams, Expression inputContextParam, List <InputVar> compiledInputVarsList)
        {
            switch (funcname)
            {
            case "f:subset":
                if (argexp is NewArrayExpression)
                {
                    if ((argexp as NewArrayExpression).Expressions.Count > 2)
                    {
                        return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Subset",
                                                                                                          new[] { typeof(object[]), typeof(int), typeof(int) }),
                                               ExCasts.WrapArguments(ExFuncs.GetArgIndex(argexp, 0)),
                                               ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 1)),
                                               ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 2))));
                    }
                    return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Subset",
                                                                                                      new[] { typeof(object[]), typeof(int) }),
                                           ExCasts.WrapArguments(ExFuncs.GetArgIndex(argexp, 0)),
                                           ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 1))));
                }
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("SubsetRuntime",
                                                                                                  new[] { typeof(object[]) }),
                                       ExCasts.WrapArguments(argexp)));

            case "f:length":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Length",
                                                                                                  new[] { typeof(object[]) }),
                                       ExCasts.WrapArguments(argexp)));

            case "f:append":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Append",
                                                                                                  new[] { typeof(object[]), typeof(object) }),
                                       ExCasts.WrapArguments(ExFuncs.GetArgIndex(argexp, 0)),
                                       ExFuncs.GetArgAsObject(ExFuncs.GetArgIndex(argexp, 1))));

            case "f:insert":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Insert",
                                                                                                  new[] { typeof(object[]), typeof(object), typeof(int) }),
                                       ExCasts.WrapArguments(ExFuncs.GetArgIndex(argexp, 0)),
                                       ExFuncs.GetArgAsObject(ExFuncs.GetArgIndex(argexp, 1)),
                                       ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 2))));

            case "f:remove":
                return(Expression.Call(Expression.Constant(this), this.GetType().GetRuntimeMethod("Remove",
                                                                                                  new[] { typeof(object[]), typeof(int) }),
                                       ExCasts.WrapArguments(ExFuncs.GetArgIndex(argexp, 0)),
                                       ExFuncs.GetArgAsInt(ExFuncs.GetArgIndex(argexp, 1))));

            default:
                throw new Exception("Func '" + funcname + "' not found in library '" + GetLibraryName() + "'");
            }
        }