当前位置: 首页>>代码示例>>C#>>正文


C# AST.Prune方法代码示例

本文整理汇总了C#中AST.Prune方法的典型用法代码示例。如果您正苦于以下问题:C# AST.Prune方法的具体用法?C# AST.Prune怎么用?C# AST.Prune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AST的用法示例。


在下文中一共展示了AST.Prune方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Nested_Nodes_Content

        public void Nested_Nodes_Content()
        {
            const string TEMPLATE = @"<c:out>Hello world</c:out>";
            var formatter = new Formatter(TEMPLATE).Parse();
            var ast = new AST(formatter.ParsedTemplate, AST.Options.DontTrackContext|AST.Options.PruneRawTexts);
            var expected = new AST()
                .Add(new TagNode("c", "out").Add(new TextNode("Hello world")));
            expected.Prune(AST.Options.PruneRawTexts);

            Assert.That(ast, Deeply.Is.EqualTo(expected));
        }
开发者ID:rslijp,项目名称:sharptiles,代码行数:11,代码来源:ASTTest.cs

示例2: Nested_Nodes_No_Variables

 public void Nested_Nodes_No_Variables()
 {
     const string TEMPLATE = @"<c:out value=""Hello""><c:out value=""World""/></c:out>";
     var formatter = new Formatter(TEMPLATE).Parse();
     var ast = new AST(formatter.ParsedTemplate, AST.Options.DontTrackContext|AST.Options.PruneRawTexts);
     var expected = new AST()
         .Add(new TagNode("c", "out").With("Value", "Hello")
             .Add(new TagNode("c", "out").With("Value", "World")));
     expected.Prune(AST.Options.PruneRawTexts);
     Assert.That(ast, Deeply.Is.EqualTo(expected));
 }
开发者ID:rslijp,项目名称:sharptiles,代码行数:11,代码来源:ASTTest.cs

示例3: Should_Still_Collect_Parse_Fragment

        public void Should_Still_Collect_Parse_Fragment()
        {
            var formatter = new Formatter("<c:out>${a}</c:out>${a}<c:out>");
            try
            {
                formatter.Parse();
                Assert.Fail();
            }
            catch (ExceptionWithContext ewc)
            {
                Assert.That(ewc.Context.Index, Is.EqualTo(26));
            }
            var ast = new AST(formatter.ParsedTemplate, AST.Options.TrimEmptyTextNodes | AST.Options.DontTrackContext|AST.Options.PruneRawTexts);

            var expected = new AST().
                Add(new TagNode("c", "out").Add(new ExpressionNode("a", "Property", null))).
                Add(new ExpressionNode("a", "Property", null));
            expected.Prune(AST.Options.PruneRawTexts);
            Assert.That(ast, Deeply.Is.EqualTo(expected));
        }
开发者ID:rslijp,项目名称:sharptiles,代码行数:20,代码来源:ASTTest.cs

示例4: Should_Track_Context

        public void Should_Track_Context()
        {
            const string TEMPLATE = @"
            <c:set var=""Status"" value=""Nice""/>
            <c:out value=""Hello"">
            <c:out value=""${Status}""/>
            </c:out>
            <c:out>World ${(A+B)*C}</c:out>";

            var formatter = new Formatter(TEMPLATE).Parse();
            var ast = new AST(formatter.ParsedTemplate, AST.Options.TrimEmptyTextNodes|AST.Options.PruneRawTexts);
            var expected = new AST().At(1,1).
                Add(new TagNode("c","set").At(2,1).With("Var","Status", new Context(2,13)).With("Value", "Nice", new Context(2, 28))).
                Add(new TagNode("c", "out").At(3, 1).With("Value", "Hello", new Context(3, 15)).
                    Add(new TagNode("c", "out").At(4, 5).With("Value", new ExpressionNode("Status", "Property", null).At(4,21)))).
                Add(new TagNode("c", "out").At(6, 1).Add(
                    new TextNode("World ").At(6,8)).Add(
                    new ExpressionNode("(A+B)*C", "Multiply", typeof(decimal)).At(6, 21).
                        Add(new ExpressionNode("(A+B)", "Brackets", typeof(decimal)).At(6, 16).
                            Add(new ExpressionNode("A+B", "Add", typeof(decimal)).At(6, 18).
                                Add(new ExpressionNode("A", "Property", null).At(6, 17)).
                                Add(new ExpressionNode("B", "Property", null).At(6, 19)))).
                            Add(new ExpressionNode("C", "Property", null).At(6, 22))));
            expected.Prune(AST.Options.PruneRawTexts);

            Assert.That(ast, Deeply.Is.EqualTo(expected));
        }
开发者ID:rslijp,项目名称:sharptiles,代码行数:27,代码来源:ASTTest.cs

示例5: Should_Collected_NestedTags

        public void Should_Collected_NestedTags()
        {
            const string TEMPLATE = @"<c:choose><c:when test=""${Yes}"">WHEN</c:when><c:otherwise>OTHERWISE</c:otherwise></c:choose>";
            var formatter = new Formatter(TEMPLATE).Parse();
            var ast = new AST(formatter.ParsedTemplate, AST.Options.DontTrackContext|AST.Options.PruneRawTexts);

            var expected = new AST()
                .Add(new TagNode("c", "choose").
                    Add(new TagNode("c", "when").With("Test",new ExpressionNode("Yes","Property",null)).Add(new TextNode("WHEN"))).
                    Add(new TagNode("c", "otherwise").Add(new TextNode("OTHERWISE")))
            );
            expected.Prune(AST.Options.PruneRawTexts);
            Assert.That(ast, Deeply.Is.EqualTo(expected));
        }
开发者ID:rslijp,项目名称:sharptiles,代码行数:14,代码来源:ASTTest.cs


注:本文中的AST.Prune方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。