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.
精彩评论