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


C# StringTemplate.Write方法代码示例

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


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

示例1: TestNewlineNormalizationInTemplateStringPC

 public void TestNewlineNormalizationInTemplateStringPC()
 {
     StringTemplate st = new StringTemplate(
             "Foo\r\n" +
             "Bar\n",
             typeof( AngleBracketTemplateLexer )
             );
     StringWriter sw = new StringWriter();
     st.Write( new AutoIndentWriter( sw, "\r\n" ) ); // force \r\n as newline
     string result = sw.ToString();
     string expecting = "Foo\r\nBar\r\n";     // expect \r\n in output
     Assert.AreEqual( expecting, result );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:StringTemplateTests.cs

示例2: TestCharLiterals

        public void TestCharLiterals()
        {
            StringTemplate st = new StringTemplate(
                    "Foo <\\r\\n><\\n><\\t> bar" + newline,
                    typeof( AngleBracketTemplateLexer )
                    );
            StringWriter sw = new StringWriter();
            st.Write( new AutoIndentWriter( sw, "\n" ) ); // force \n as newline
            string result = sw.ToString();
            string expecting = "Foo \n\n\t bar\n";     // expect \n in output
            Assert.AreEqual( expecting, result );

            st = new StringTemplate(
                    "Foo $\\n$$\\t$ bar" + newline );
            sw = new StringWriter();
            st.Write( new AutoIndentWriter( sw, "\n" ) ); // force \n as newline
            expecting = "Foo \n\t bar\n";     // expect \n in output
            result = sw.ToString();
            Assert.AreEqual( expecting, result );

            st = new StringTemplate(
                    "Foo$\\ $bar$\\n$" );
            sw = new StringWriter();
            st.Write( new AutoIndentWriter( sw, "\n" ) ); // force \n as newline
            result = sw.ToString();
            expecting = "Foo bar\n"; // force \n
            Assert.AreEqual( expecting, result );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:28,代码来源:StringTemplateTests.cs

示例3: TestNewlineNormalizationInAttribute

 public void TestNewlineNormalizationInAttribute()
 {
     StringTemplate st = new StringTemplate(
             "Foo\r\n" +
             "<name>\n",
             typeof( AngleBracketTemplateLexer )
             );
     st.SetAttribute( "name", "a\nb\r\nc" );
     StringWriter sw = new StringWriter();
     st.Write( new AutoIndentWriter( sw, "\n" ) ); // force \n as newline
     string result = sw.ToString();
     string expecting = "Foo\na\nb\nc\n";     // expect \n in output
     Assert.AreEqual( expecting, result );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:14,代码来源:StringTemplateTests.cs

示例4: TestLineBreakNoWhiteSpaceDollar

 public void TestLineBreakNoWhiteSpaceDollar()
 {
     StringTemplate st = new StringTemplate(
             "Foo $\\\\$" + newline +
             "bar" + newline,
             typeof(DefaultTemplateLexer)
             );
     StringWriter sw = new StringWriter();
     st.Write(new AutoIndentWriter(sw, "\n")); // force \n as newline
     string result = sw.ToString();
     string expecting = "Foo bar\n";     // expect \n in output
     Assert.AreEqual(expecting, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:StringTemplateTests.cs

示例5: TestLineBreak2

 public void TestLineBreak2()
 {
     StringTemplate st = new StringTemplate(
             "Foo <\\\\>       " + newline +
             "  \t  bar" + newline,
             typeof(AngleBracketTemplateLexer)
             );
     StringWriter sw = new StringWriter();
     st.Write(new AutoIndentWriter(sw, "\n")); // force \n as newline
     string result = sw.ToString();
     string expecting = "Foo bar\n";     // expect \n in output
     Assert.AreEqual(expecting, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:StringTemplateTests.cs

示例6: TestAlternativeWriter

 public void TestAlternativeWriter()
 {
     StringBuilder buf = new StringBuilder();
     IStringTemplateWriter w = new AlternativeWriter( buf );
     StringTemplateGroup group =
             new StringTemplateGroup( "test" );
     group.DefineTemplate( "bold", "<b>$x$</b>" );
     StringTemplate name = new StringTemplate( group, "$name:bold(x=name)$" );
     name.SetAttribute( "name", "Terence" );
     name.Write( w );
     Assert.AreEqual( "<b>Terence</b>", buf.ToString() );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:StringTemplateTests.cs

示例7: WriteTemplate

        protected virtual int WriteTemplate(StringTemplate self, StringTemplate stToWrite, IStringTemplateWriter @out)
        {
            int n = 0;
            /* failsafe: perhaps enclosing instance not set
             * Or, it could be set to another context!  This occurs
             * when you store a template instance as an attribute of more
             * than one template (like both a header file and C file when
             * generating C code).  It must execute within the context of
             * the enclosing template.
             */
            stToWrite.EnclosingInstance = self;
            // if self is found up the enclosing instance chain, then infinite recursion
            if (StringTemplate.LintMode && StringTemplate.IsRecursiveEnclosingInstance(stToWrite))
            {
                // throw exception since sometimes eval keeps going even after I ignore this write of o.
                throw new InvalidOperationException("infinite recursion to " +
                        stToWrite.GetTemplateDeclaratorString() + " referenced in " +
                        stToWrite.EnclosingInstance.TemplateDeclaratorString +
                        "; stack trace:" + Environment.NewLine + stToWrite.GetEnclosingInstanceStackTrace());
            }
            else
            {
                // if we have a wrap string, then inform writer it might need to wrap
                if (_wrapString != null)
                {
                    n = @out.WriteWrapSeparator(_wrapString);
                }

                // check if formatting needs to be applied to the stToWrite
                if (_formatString != null)
                {
                    IAttributeRenderer renderer = self.GetAttributeRenderer(typeof(string));
                    if (renderer != null)
                    {
                        /* you pay a penalty for applying format option to a template
                         * because the template must be written to a temp StringWriter so it can
                         * be formatted before being written to the real output.
                         */
                        StringWriter buf = new StringWriter();
                        IStringTemplateWriter sw = self.Group.GetStringTemplateWriter(buf);
                        stToWrite.Write(sw);
                        n = @out.Write(renderer.ToString(buf.ToString(), _formatString));
                        return n;
                    }
                }

                n = stToWrite.Write(@out);
            }

            return n;
        }
开发者ID:bszafko,项目名称:antlrcs,代码行数:51,代码来源:ASTExpr.cs


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