本文整理汇总了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(" / ");
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}