/// <summary> /// Evaluates the specified expression. /// </summary> /// <param name="expression">The expression.</param> /// <returns>Result of the expression evaluated</returns> public ExpressionResult Evaluate(Expression expression) { values.Clear(); result = new ExpressionResult(); // Small optim, if LiteralExpression, we perform a direct eval. var literalExpression = expression as LiteralExpression; if (literalExpression != null) { Visit(literalExpression); } else { VisitDynamic(expression); } if (values.Count == 1) result.Value = values.Pop(); else { result.Error("Cannot evaluate expression {0}", expression.Span, expression); } return result; }