Exemplo n.º 1
0
        private EvaluationResult Evaluate(EvaluationResult left, OperatorExpression op, EvaluationResult right, NumericPrecision numericPrecision)
        {
            Exception exception = null;

            try
            {
                if (left == null || op == null || right == null)
                {
                    return(new EvaluationResult(EvaluationType.Null, null));
                }
                if (left.Type == EvaluationType.Boolean && right.Type == EvaluationType.Boolean)
                {
                    return(EvaluateBools(left.AsBoolean().Value, op, right.AsBoolean().Value));
                }
                if (left.Type == EvaluationType.DateTime && right.Type == EvaluationType.DateTime)
                {
                    return(EvaluateDates(left.AsDateTime().Value, op, right.AsDateTime().Value));
                }
                if (left.Type == EvaluationType.String && right.Type == EvaluationType.String)
                {
                    return(EvaluateStrings(left.AsString(), op, right.AsString()));
                }
                if (left.Type == EvaluationType.Int && right.Type == EvaluationType.Int)
                {
                    return(EvaluateInts(left.AsInt().Value, op, right.AsInt().Value));
                }
                var leftIsNumeric  = left.Type == EvaluationType.Float || left.Type == EvaluationType.Int;
                var rightIsNumeric = right.Type == EvaluationType.Float || right.Type == EvaluationType.Int;
                if (leftIsNumeric && rightIsNumeric)
                {
                    var leftNumeric  = left.AsRealNumber(numericPrecision);
                    var rightNumeric = right.AsRealNumber(numericPrecision);
                    return(EvaluateFloats(leftNumeric, op, rightNumeric));
                }
            }
            catch (Exception e)
            {
                exception = e;
            }
            throw new EvaluationException(left, op, right, exception);
        }