Exemplo n.º 1
0
        public void SubstitutionTestId()
        {
            BaseExpression expr  = BaseExpression.Parse("x + y + z");
            BaseExpression expr2 = expr.Subst(new Dictionary <string, BaseExpression>());

            Assert.AreEqual(expr.ToString(), expr2.ToString());
        }
Exemplo n.º 2
0
        public override BaseExpression Visit(BaseExpression expression)
        {
            if (expression.IsConstant)
            {
                var v = expression.TryStaticEvaluate();
                if (v.HasValue)
                {
                    // Do not substitute the constant value if it is a longer string than the expression
                    if (!_allowLonger && v.ToString().Length > expression.ToString().Length)
                    {
                        return(base.Visit(expression));
                    }

                    if (v.Value.Type == Type.Number)
                    {
                        return(base.Visit(new ConstantNumber(v.Value.Number)));
                    }
                    else
                    {
                        return(base.Visit(new ConstantString(v.Value.String)));
                    }
                }
            }

            return(base.Visit(expression));
        }
Exemplo n.º 3
0
        public void SubstitutionTestId2()
        {
            BaseExpression expr  = BaseExpression.Parse("1 + 2 + x + y");
            var            subst = new Dictionary <string, BaseExpression>();

            subst["a"] = new IntegerExpression(3);
            subst["b"] = new IntegerExpression(9);
            BaseExpression expr2 = expr.Subst(subst);

            Assert.AreEqual(expr.ToString(), expr2.ToString());
        }
Exemplo n.º 4
0
 public override string ToString()
 {
     return(_expr.ToString());
 }
Exemplo n.º 5
0
 /// <summary>
 /// Define a conditional transformation
 /// </summary>
 /// <param name="expression">An expression</param>
 /// <returns>The transformation for chaining</returns>
 public Transformation IfCondition(BaseExpression expression)
 {
     return(IfCondition(expression.ToString()));
 }
Exemplo n.º 6
0
 public override string ToCode()
 {
     return(BaseExpression != null?BaseExpression.ToString() : RepresentedType != null?RepresentedType.ToString() : "null");
 }
Exemplo n.º 7
0
 public override string ToCode()
 {
     return(BaseExpression == null ? (Variable == null ?"null":Variable.ToString(false)) : BaseExpression.ToString());
 }