Exemplo n.º 1
0
        public static object Evaluate(ExpressionContext context, string expr, IExpressionPropertyFinder finder)
        {
            //try {
            CommonAST ast;
            if (!astCache.ContainsKey(expr))
            {
                ExpressionParser parser = CreateParser(expr);
                parser.expr();
                ast = parser.getAST();
                lock (astCache)
                {
                    if (!astCache.ContainsKey(expr))
                        astCache.Add(expr, ast);
                }
            }
            else
            {
                ast = astCache[expr];
            }

            //Console.WriteLine(ast.ToTree());
            try
            {
                ExpressionTreeParser my = new ExpressionTreeParser(context, finder);
                return my.Evaluate(ast);
            }
            catch (Exception e)
            {
                string msg = string.Format("An error accured during evaluation of '{0}'", expr);
                log.Fatal(msg, e);
                throw new Exception(msg, e);
            }
        }
 /// <summary>
 /// Ctor for tree walker.
 /// </summary>
 /// <param name="context">Expression context</param>
 /// <param name="finderInstance">Finder instance</param>
 public ExpressionTreeParser(ExpressionContext context, IExpressionPropertyFinder finderInstance)
 {
     this.finderInstance = finderInstance;
     this.context = context;
 }