Example #1
0
 public void AddSeveralLiterals()
 {
     var builder = new ExpressionBuilder();
     builder.AppendLiteral("hello");
     builder.AppendLiteral("world");
     Assert.AreEqual("\"helloworld\"", builder.ToCode());
 }
Example #2
0
 public void CodeEndsUpConcatinated()
 {
     var builder = new ExpressionBuilder();
     builder.AppendExpression("x");
     builder.AppendExpression("y");
     builder.AppendExpression("z");
     Assert.AreEqual("string.Concat(x,y,z)", builder.ToCode());
 }
Example #3
0
        internal static AttributeNode AddMethodCallingToAttributeValue(AttributeNode node, string method)
        {
            var snippets = new Snippets {new Snippet {Value = method + "("}};
            snippets.AddRange(node.AsCodeInverted());
            snippets.Add(new Snippet {Value= ")"});

            var builder = new ExpressionBuilder();
            builder.AppendExpression(snippets);
            var listNodes=new List<Node> {new ExpressionNode(snippets)};
            return new AttributeNode(node.Name, listNodes);
        }
Example #4
0
 public static Snippets AsCodeInverted(this AttributeNode attr)
 {
     var expression = new ExpressionBuilder();
     foreach (var node in attr.Nodes)
     {
         if (node is TextNode)
         {
             expression.AppendLiteral(((TextNode)node).Text);
         }
         else if (node is ExpressionNode)
         {
             expression.AppendExpression(((ExpressionNode)node).Code);
         }
         else if (node is EntityNode)
         {
             expression.AppendLiteral("&" + ((EntityNode)node).Name + ";");
         }
     }
     return new Snippets(expression.ToCode());
 }
Example #5
0
 public void TextIsEscaped()
 {
     var builder = new ExpressionBuilder();
     builder.AppendLiteral("\"\\\t");
     Assert.AreEqual("\"\\\"\\\\\\t\"", builder.ToCode());
 }