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


C# StringTemplate.GetInstanceOf方法代码示例

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


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

示例1: TestListLiteralWithEmptyElements

 public void TestListLiteralWithEmptyElements()
 {
     StringTemplate e = new StringTemplate(
             "$[\"Ter\",,\"Jesse\"]:{n | $i$:$n$}; separator=\", \", null=\"\"$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "phones", "1" );
     e.SetAttribute( "salaries", "big" );
     string expecting = "1:Ter, 2:, 3:Jesse";
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:StringTemplateTests.cs

示例2: TestCatWithTemplateApplicationAsElement

 public void TestCatWithTemplateApplicationAsElement()
 {
     StringTemplate e = new StringTemplate(
             "$[names:{$it$!},phones]; separator=\", \"$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "phones", "1" );
     e.SetAttribute( "phones", "2" );
     string expecting = "Ter!, Tom!, 1, 2";
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:StringTemplateTests.cs

示例3: WriteSubTemplate

 protected virtual int WriteSubTemplate( StringTemplate self,
     IStringTemplateWriter @out,
     StringTemplate subtemplate)
 {
     /* To evaluate the IF chunk, make a new instance whose enclosingInstance
      * points at 'self' so get attribute works.  Otherwise, enclosingInstance
      * points at the template used to make the precompiled code.  We need a
      * new template instance every time we exec this chunk to get the new
      * "enclosing instance" pointer.
      */
     StringTemplate s = subtemplate.GetInstanceOf();
     s.EnclosingInstance = self;
     // make sure we evaluate in context of enclosing template's
     // group so polymorphism works. :)
     s.Group = self.Group;
     s.NativeGroup = self.NativeGroup;
     return s.Write( @out );
 }
开发者ID:benpriebe,项目名称:TypeSql,代码行数:18,代码来源:ConditionalExpr.cs

示例4: TestCatListAndEmptyAttributes

 public void TestCatListAndEmptyAttributes()
 {
     // + is overloaded to be cat strings and cat lists so the
     // two operands (from left to right) determine which way it
     // goes.  In this case, x+mine is a list so everything from their
     // to the right becomes list cat.
     StringTemplate e = new StringTemplate(
             "$[x,mine,y,yours,z]; separator=\", \"$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "mine", "1" );
     e.SetAttribute( "mine", "2" );
     e.SetAttribute( "mine", "3" );
     e.SetAttribute( "yours", "a" );
     string expecting = "1, 2, 3, a";
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:17,代码来源:StringTemplateTests.cs

示例5: TestCatWithIFAsElement

 public void TestCatWithIFAsElement()
 {
     StringTemplate e = new StringTemplate(
             "$[{$if(names)$doh$endif$},phones]; separator=\", \"$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "phones", "1" );
     e.SetAttribute( "phones", "2" );
     string expecting = "doh, 1, 2";
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:StringTemplateTests.cs

示例6: TestTruncOp

 public void TestTruncOp()
 {
     StringTemplate e = new StringTemplate(
             "$trunc(names); separator=\", \"$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "names", "Sriram" );
     string expecting = "Ter, Tom";
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:StringTemplateTests.cs

示例7: TestCat2AttributesWithApply

 public void TestCat2AttributesWithApply()
 {
     StringTemplate e = new StringTemplate(
             "$[names,phones]:{a|$a$.}$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "phones", "1" );
     e.SetAttribute( "phones", "2" );
     string expecting = "Ter.Tom.1.2.";
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:StringTemplateTests.cs

示例8: TestParallelAttributeIterationWithMissingArgs

 public void TestParallelAttributeIterationWithMissingArgs()
 {
     IStringTemplateErrorListener errors = new ErrorBuffer();
     StringTemplate e = new StringTemplate(
             "$names,phones,salaries:{[email protected]$p$}; separator=\", \"$"
         );
     e.ErrorListener = errors;
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "phones", "2" );
     e.SetAttribute( "salaries", "big" );
     e.ToString(); // generate the error
     string errorExpecting = "missing arguments in anonymous template in context [anonymous]";
     Assert.AreEqual( errorExpecting, errors.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:StringTemplateTests.cs

示例9: TestParallelAttributeIterationWithNullValue

 public void TestParallelAttributeIterationWithNullValue()
 {
     StringTemplate e = new StringTemplate(
             "$names,phones,salaries:{n,p,s | [email protected]$p$: $s$\n}$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "names", "Sriram" );
     e.SetAttribute( "phones", new List<object>( new object[] { "1", null, "3" } ) );
     e.SetAttribute( "salaries", "big" );
     e.SetAttribute( "salaries", "huge" );
     e.SetAttribute( "salaries", "enormous" );
     string expecting = "[email protected]: big" + newline +
                        "[email protected]: huge" + newline +
                        "[email protected]: enormous" + newline;
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:18,代码来源:StringTemplateTests.cs

示例10: TestParallelAttributeIterationHasI

 public void TestParallelAttributeIterationHasI()
 {
     StringTemplate e = new StringTemplate(
             "$names,phones,salaries:{n,p,s | $i0$. [email protected]$p$: $s$\n}$"
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "phones", "1" );
     e.SetAttribute( "phones", "2" );
     e.SetAttribute( "salaries", "big" );
     e.SetAttribute( "salaries", "huge" );
     string expecting = "0. [email protected]: big" + newline + "1. [email protected]: huge" + newline;
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:StringTemplateTests.cs

示例11: TestParallelAttributeIterationWithMismatchArgListSizes

 public void TestParallelAttributeIterationWithMismatchArgListSizes()
 {
     IStringTemplateErrorListener errors = new ErrorBuffer();
     StringTemplate e = new StringTemplate(
             "$names,phones,salaries:{n,p | [email protected]$p$}; separator=\", \"$"
         );
     e.ErrorListener = errors;
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "phones", "1" );
     e.SetAttribute( "phones", "2" );
     e.SetAttribute( "salaries", "big" );
     string expecting = "[email protected], [email protected]";
     Assert.AreEqual( expecting, e.ToString() );
     string errorExpecting = "number of arguments [n, p] mismatch between attribute list and anonymous template in context [anonymous]";
     Assert.AreEqual( errorExpecting, errors.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:18,代码来源:StringTemplateTests.cs

示例12: TestNestedOp

 public void TestNestedOp()
 {
     StringTemplate e = new StringTemplate(
             "$first(rest(names))$" // gets 2nd element
         );
     e = e.GetInstanceOf();
     e.SetAttribute( "names", "Ter" );
     e.SetAttribute( "names", "Tom" );
     e.SetAttribute( "names", "Sriram" );
     string expecting = "Tom";
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:StringTemplateTests.cs

示例13: TestNestedIF

        public void TestNestedIF()
        {
            StringTemplate e = new StringTemplate(
                    "$if(title)$" + newline +
                    "foo" + newline +
                    "$else$" + newline +
                    "$if(header)$" + newline +
                    "bar" + newline +
                    "$else$" + newline +
                    "blort" + newline +
                    "$endif$" + newline +
                    "$endif$"
                );
            e.SetAttribute( "title", "sample" );
            string expecting = "foo";
            Assert.AreEqual( expecting, e.ToString() );

            e = e.GetInstanceOf();
            e.SetAttribute( "header", "more" );
            expecting = "bar";
            Assert.AreEqual( expecting, e.ToString() );

            e = e.GetInstanceOf();
            expecting = "blort";
            Assert.AreEqual( expecting, e.ToString() );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:26,代码来源:StringTemplateTests.cs

示例14: TestApplyAnonymousTemplateToMapAndSet

        public void TestApplyAnonymousTemplateToMapAndSet()
        {
            StringTemplate st =
                    new StringTemplate( "$items:{<li>$it$</li>}$" );
            IDictionary m = new SortedList<object, object>();
            m["a"] = "1";
            m["b"] = "2";
            m["c"] = "3";
            st.SetAttribute( "items", m );
            string expecting = "<li>1</li><li>2</li><li>3</li>";
            Assert.AreEqual( expecting, st.ToString() );

            st = st.GetInstanceOf();
            HashSet<object> s = new HashSet<object>();
            s.Add( "1" );
            s.Add( "2" );
            s.Add( "3" );
            st.SetAttribute( "items", s );
            //expecting = "<li>3</li><li>2</li><li>1</li>";
            expecting = "<li>1</li><li>2</li><li>3</li>";
            Assert.AreEqual( expecting, st.ToString() );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:22,代码来源:StringTemplateTests.cs

示例15: TestStripOpOfNull

 public void TestStripOpOfNull()
 {
     StringTemplate e = new StringTemplate(
             "$strip(data)$"
         );
     e = e.GetInstanceOf();
     string expecting = ""; // nulls are skipped
     Assert.AreEqual( expecting, e.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:9,代码来源:StringTemplateTests.cs


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