public ReportMeta(RdlReport reportElement) { try { ReportElement = reportElement; ReportParameters = new Resolvable<string, ReportParameter>(ReportParameters_Resolve, StringComparer.InvariantCultureIgnoreCase); DataSources = new Resolvable<string, IResolvedDataSource>(DataSources_Resolve, StringComparer.InvariantCultureIgnoreCase); ReportExpressionEvaluator = CreateExpressionEvaluator(); // Depends on resolvable collections } catch (Exception) { if (ReportExpressionEvaluator != null) ReportExpressionEvaluator.Dispose(); throw; } }
private static void Test(double expected, string expression) { Assert.AreEqual(expected, Evaluator.Eval(expression)); }
public static double EvaluateExpression(Expression expression) { var identifier = expression as IdentifierExpression; if (identifier != null) { return(0); } else { var number = expression as NumberExpression; if (number != null) { var integer = expression as IntegerNumberExpression; if (integer != null) { return(integer.Value); } else { var real = expression as RealNumberExpression; if (real != null) { return(real.Value); } } } else { var parenthesis = expression as ParenthesisExpression; if (parenthesis != null) { return(Evaluator.EvaluateExpression(parenthesis.Expression)); } else { var binaryExpression = expression as BinaryExpression; if (binaryExpression != null) { var left = Evaluator.EvaluateExpression(binaryExpression.Left); var right = Evaluator.EvaluateExpression(binaryExpression.Right); var operation = ResolveOperation(binaryExpression); switch (operation) { case BinaryOperation.Add: return(left + right); case BinaryOperation.Subtract: return(left - right); case BinaryOperation.Multiply: return(left * right); case BinaryOperation.Divide: return(left / right); case BinaryOperation.Modulo: return(left % right); case BinaryOperation.Power: return(Math.Pow(left, right)); } } } } } throw new Exception(); }