开发者

String Template - Results are different when Reading from File / Reading from String

string template = "group simple; apply(it) ::= << $it:bold():italics()$ >>开发者_JS百科 ";
StringTemplateGroup stg = new StringTemplateGroup(new StringReader(template));
stg.DefineTemplate("bold", "<b>$it$</b>");
stg.DefineTemplate("italics", "<i>$it$</i>");
StringTemplate st = stg.GetInstanceOf("apply");
st.SetAttribute("it", "name");
Console.WriteLine(st.ToString());

The result of above is $it:bold():italics()$ I was expecting <i><b>name</b></i>

But when the template is read from file, it works as expected.

StringTemplateGroup stg = new StringTemplateGroup("page", "../../Templates");
stg.DefineTemplate("bold", "<b>$it$</b>");
stg.DefineTemplate("italics", "<i>$it$</i>");
StringTemplate st = stg.GetInstanceOf("apply"); //apply.st => $it:bold():italics()$
st.SetAttribute("it", "name");
Console.WriteLine(st.ToString());

Output is as expected <i><b>name</b></i>

Why isn't it working in the first case? Am I missing something?


<...> is default delimiter in group files. Note StringTemplate v4 will be out in a week or so.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜