public void SubstitutionTestId() { BaseExpression expr = BaseExpression.Parse("x + y + z"); BaseExpression expr2 = expr.Subst(new Dictionary <string, BaseExpression>()); Assert.AreEqual(expr.ToString(), expr2.ToString()); }
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)); }
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()); }
public override string ToString() { return(_expr.ToString()); }
/// <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())); }
public override string ToCode() { return(BaseExpression != null?BaseExpression.ToString() : RepresentedType != null?RepresentedType.ToString() : "null"); }
public override string ToCode() { return(BaseExpression == null ? (Variable == null ?"null":Variable.ToString(false)) : BaseExpression.ToString()); }