Jakub Šturc
Jakub Šturc

Reputation: 35767

How to force StringTemplate to evaluate attribute within attribute?

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?

Upvotes: 4

Views: 459

Answers (1)

Jakub Šturc
Jakub Šturc

Reputation: 35767

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 rtm twice before asking. I promise :-)

Upvotes: 5

Related Questions