Exemplo n.º 1
0
        public Func <TReturn> Compile <TReturn>(string formula)
        {
            var definition = new LambdaTypeDefinition {
                ReturnedType = typeof(TReturn)
            };

            return(CompileToExpression <Func <TReturn> >(formula, definition)
                   .Compile());
        }
Exemplo n.º 2
0
        public Func <TReturn> Compile <TReturn>(string formula)
        {
            var definition = new LambdaTypeDefinition {
                ReturnedType = typeof(TReturn)
            };

            var compileToExpression = CompileToExpression <Func <TReturn> >(formula, definition);

            return(compileToExpression != null?compileToExpression.Compile() : null);
        }
Exemplo n.º 3
0
        internal Expression <T> CompileToExpression <T>(string formula, LambdaTypeDefinition definition)
        {
            BuildInfo.Clear();

            var tree = Parse(formula);

            if (tree == null)
            {
                return(null);
            }

            return(_translator.Translate <T>(tree, definition, CallProvider, BuildInfo));
        }
Exemplo n.º 4
0
        public Expression <T> Translate <T>(CommonTree lambdaTree,
                                            LambdaTypeDefinition definition,
                                            ICallProvider callProvider,
                                            BuildInfo buildInfo)
        {
            CallProvider = callProvider ?? EmptyCallProvider.Empty;
            Definition   = definition;
            BuildInfo    = buildInfo;

            // Prepare params
            Parameters = definition.Params.Select(
                p => Expression.Parameter(p.ParamType, p.Name)).ToList();

            // Prepare this param
            if (definition.ThisType != null)
            {
                var thisParam = Expression.Parameter(definition.ThisType, "this");
                This = thisParam;
                Parameters.Insert(0, thisParam);
            }
            else
            {
                This = null;
            }

            Expression <T> expression = null;

            try
            {
                expression = TranslateInternal <T>(lambdaTree);
            }
            catch (FormulaCompilerException e)
            {
                BuildInfo.Log(e.Message, FormulaCompilerBuildInfoLevels.Error);
            }

            return(expression);
        }
Exemplo n.º 5
0
 internal CompilableLambda(LambdaTypeDefinition definition, FormulaCompiler compiler)
 {
     Definition = definition;
     Compiler   = compiler;
 }