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


C# Template.Write方法代码示例

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


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

示例1: ToString

        public override sealed string ToString()
        {
            if (Engine.ResultTemplate == null)
                return base.ToString();

            Errors.Clear();

            try
            {
                _results = new ResultDB(_seed);
                var template = new Template(Engine.ResultTemplate.Replace(".$", "$").Replace("$this$", Engine.Name), '$', '$');
                template.Add("this", this);
                template.Add("dyce", _results);
                template.Group.RegisterRenderer(typeof(object), new BasicFormatRenderer());
                StringWriter writer = new StringWriter();
                ErrorListener listener = new ErrorListener();
                template.Write(writer, listener);

                if (listener.HasErrors)
                    Errors.AddRange(listener.Errors);

                if (Errors.Any())
                    return Errors.JoinToString(" / ");

                if (_results.Results.Any())
                    RaisePropertyChanged(() => SubResults);

                return PostProcess(writer.ToString());
            }
            catch (Exception ex)
            {
                Errors.Add(new ResultError(ex, Engine.ResultTemplate));
                return Errors.JoinToString(" / ");
            }
        }
开发者ID:bjennings76,项目名称:DyCE,代码行数:35,代码来源:ResultBase.cs

示例2: TestNewlineNormalizationInTemplateStringPC

 public void TestNewlineNormalizationInTemplateStringPC()
 {
     Template st = new Template(
             "Foo\r\n" +
             "Bar\n"
             );
     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:mahanteshck,项目名称:antlrcs,代码行数:12,代码来源:TestWhitespace.cs

示例3: TestCharLiterals

        public void TestCharLiterals()
        {
            Template st = new Template(
                    "Foo <\\n><\\n><\\t> bar\n"
                    );
            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 Template(
                    "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 Template(
                    "Foo<\\ >bar<\\n>");
            sw = new StringWriter();
            st.Write(new AutoIndentWriter(sw, "\n")); // force \n as newline
            result = sw.ToString();
            expecting = "Foo bar\n"; // forced \n
            Assert.AreEqual(expecting, result);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:27,代码来源:TestCoreBasics.cs

示例4: TestNewlineNormalizationInAttribute

 public void TestNewlineNormalizationInAttribute()
 {
     Template st = new Template(
             "Foo\r\n" +
             "<name>\n"
             );
     st.Add("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:mahanteshck,项目名称:antlrcs,代码行数:13,代码来源:TestWhitespace.cs

示例5: TestLineBreakNoWhiteSpace

 public void TestLineBreakNoWhiteSpace()
 {
     Template st = new Template(
             "Foo <\\\\>" + newline +
             "bar\n"
             );
     StringWriter sw = new StringWriter();
     st.Write(new AutoIndentWriter(sw, "\n")); // force \n as newline
     string result = sw.ToString();
     string expecting = "Foo bar\n";
     Assert.AreEqual(expecting, result);
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:12,代码来源:TestWhitespace.cs

示例6: TestSeparatorEmittedForEmptyIteratorValue2

 public void TestSeparatorEmittedForEmptyIteratorValue2()
 {
     Template st = new Template(
         "<values; separator=\" \">"
     );
     st.Add("values", new string[] { "x", string.Empty, "y" });
     StringWriter sw = new StringWriter();
     st.Write(new AutoIndentWriter(sw));
     string result = sw.ToString();
     string expecting = "x  y";
     Assert.AreEqual(expecting, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:TestNullAndEmptyValues.cs

示例7: TestSeparatorEmittedForEmptyIteratorValue

 public void TestSeparatorEmittedForEmptyIteratorValue()
 {
     Template st = new Template(
         "<values:{v|<if(v)>x<endif>}; separator=\" \">"
     );
     st.Add("values", new bool[] { true, false, true });
     StringWriter sw = new StringWriter();
     st.Write(new AutoIndentWriter(sw));
     string result = sw.ToString();
     string expecting = "x  x";
     Assert.AreEqual(expecting, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:TestNullAndEmptyValues.cs

示例8: Write

        public virtual void Write(Template code, string fileName)
        {
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                using (TextWriter w = tool.GetOutputFileWriter(g, fileName))
                {
                    ITemplateWriter wr = new AutoIndentWriter(w);
                    wr.LineWidth = lineWidth;
                    code.Write(wr);
                }

                stopwatch.Stop();
            }
            catch (IOException ioe)
            {
                tool.errMgr.ToolError(ErrorType.CANNOT_WRITE_FILE,
                                      ioe,
                                      fileName);
            }
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:21,代码来源:CodeGenerator.cs


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