Exemplo n.º 1
0
        public int ExpressiveParserMethod(Dictionary <string, object> input, string inputString)
        {
            var expression = new Expressive.Expression(inputString);
            var result     = expression.Evaluate(input);

            return(Convert.ToInt16(result));
        }
Exemplo n.º 2
0
        public void SumShouldUseZeroInsteadOfNull()
        {
            var arguments = new Dictionary <string, object>
            {
                ["Value1"] = 1.1m,
                ["Value2"] = null
            };
            var expression = new Expressive.Expression("Sum([Value1], [Value2])");

            var result = expression.Evaluate(arguments);

            Assert.IsInstanceOfType(result, typeof(decimal?));
            Assert.AreEqual(1.1m, result);
        }
Exemplo n.º 3
0
        public void SumShouldHandleIEnumerableWithNulls()
        {
            var arguments = new Dictionary <string, object>
            {
                ["Value"] = new List <decimal?> {
                    1.0m, null, 2.5m
                },
                ["Value1"] = 3m
            };
            var expression = new Expressive.Expression("Sum([Value], [Value1])");

            var result = expression.Evaluate(arguments);

            Assert.IsInstanceOfType(result, typeof(decimal?));
            Assert.AreEqual(6.5m, result);
        }
Exemplo n.º 4
0
        public static ExpressionSyntax ForceOptimization(this ExpressionSyntax exp)
        {
            if (exp is ArgumentExpression arg)
            {
                return(ForceOptimization(arg.Value));
            }
            if (exp is StringLiteralExpressionSyntax)
            {
                return(exp.AsOptimized());
            }

            var result = new Expressive.Expression(exp.ExpressionString).Evaluate();

            if (result is float f)
            {
                return(new SingleLiteralExpressionSyntax(f).AsOptimized());
            }
            return(new VeinSyntax().LiteralExpression.End().Parse($"{result}").AsOptimized());
        }