I could’ve sworn I saw some articles a while ago about imperfect but useful string interpolation methods for C, but no such luck right now. However, there’s Razor, which does more or less what I want.
Suppose you have a database client application with tickets, and e-mail notifications are to be sent whenever tickets get created, significant parameters change, etc. The user would like to customize the wording of those notification e-mails, which would be easiest using string interpolation, i.e. accessing various properties of the ticket object from within the string, like so:
Dear
@user,the ticket
@ticket.ID(@ticket.URL) has changed in priority from@previousTicket.priorityto@currentTicket.priority.
What I’d like is a method that I pass various objects (in this case user, oldTicket and ticket), and have it evaluate the string and get the necessary properties through reflection.
While I’m sure there’s many engines out there that do this, we settled on Castle NVelocity, and it does it really well.
http://www.castleproject.org/others/nvelocity/usingit.html
It accepts the data via name/value pairs, and runs it through a template. It can be used for generating all kinds of textual output in memory. It supports includes, conditional sections, and also repeating data (eg. lines on an order).
Most importantly, it’s damn easy to use.