當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。