If you are ok assigning a local variable that contains the data you use to replace the template parameters, you can use the C# 6.0 string interpolation feature.
The basic principle is that you can do fairly advanced string replacement logic based on input data.
Simple example:
string name = "John";
string message = $"Hello, my name is {name}."
Complex example:
List strings = ...
string summary = $"There are {strings.Count} strings. "
+ $"The average length is {strings.Select(s => s.Length).Average()}"
Drawbacks:
- No support for dynamic templates (e.g. from a resources file)
(Major) advantages:
- It enforces compile time checks on your template replacement.
A nice open source solution that has almost the same syntax, is Mustache. It has two available C# implementations from what I could find - mustache-sharp and Nustache.
I have worked with mustache-sharp
and found that it does not have the same power as the string interpolation, but comes close. E.g. you can do the following (stolen from it's github page).
Hello, {{Customer.Name}}
{{#newline}}
{{#newline}}
{{#with Order}}
{{#if LineItems}}
Here is a summary of your previous order:
{{#newline}}
{{#newline}}
{{#each LineItems}}
{{ProductName}}: {{UnitPrice:C}} x {{Quantity}}
{{#newline}}
{{/each}}
{{#newline}}
Your total was {{Total:C}}.
{{#else}}
You do not have any recent purchases.
{{/if}}
{{/with}}