/// <inheritdoc/>
        protected override IConstantExpression Bind(ConstExpressionContext node, IConstant parent)
        {
            var type = GetExpressionType(node);

            var builder = new ConstantExpressionBuilder()
                          .SetNode(node)
                          .SetParent(parent)
                          .SetRawValue(node.value?.Text)
                          .SetType(type);

            return(builder.Build());
        }
Exemplo n.º 2
0
        private InvocationExpressionBuilder MakeRoundingExpression(ExpressionBuilder inner,
                                                                   ConstantExpressionBuilder decimals,
                                                                   MemberExpressionBuilder direction)
        {
            if (direction != null)
            {
                string roundingFunction;

                if (direction.IsEquivalent("BigDecimal.ROUND_UP"))
                {
                    roundingFunction = "Ceiling";
                }
                else if (direction.IsEquivalent("BigDecimal.ROUND_DOWN"))
                {
                    roundingFunction = "Floor";
                }
                else
                {
                    throw new NotSupportedException();
                }

                var invocation = new InvocationExpressionBuilder(roundingFunction);
                invocation.Arguments.Add(inner);
                invocation.Arguments.Add(decimals);

                return(invocation);
            }
            else
            {
                var invocation = new InvocationExpressionBuilder("System.Math.Round");
                invocation.Arguments.Add(inner);
                invocation.Arguments.Add(decimals);
                invocation.Arguments.Add(new MemberExpressionBuilder("System", "MidpointRounding", "AwayFromZero"));

                return(invocation);
            }
        }