views:

154

answers:

1

I have the following code:

StringTemplate st = new StringTemplate("$msg$");
st.SetAttribute("msg", "Hello $usr$");
st.SetAttribute("usr", "Jakub");
Console.WriteLine(st); 
// current output:  "Hello $usr$"
// expected output: "Hello Jakub"

Do anybody know how to force StringTemplate to evaluate $usr$ attribute?

+2  A: 

The correct solution should look following.

StringTemplate st = new StringTemplate("$msg$");
st.SetAttribute("msg", new StringTemplate("Hello $usr$"));
st.SetAttribute("usr", "Jakub");
Console.WriteLine(st); 
// current output:  "Hello Jakub"
// expected output: "Hello Jakub"

Next time I'll rtfm twice before asking. I promise :-)

Jakub Šturc