using System.Collections.Generic;
public static void Main()
var myValues = new Dictionary<string, string>{{"name", "Horatio"}};
const string myTemplate = "My name is {{name}}. I like my templates to start with {{}} and end with }}";
var myTemplateResult = TemplateOnDemand.ApplyStringTemplate(myTemplate, key => myValues[key]);
Console.WriteLine(myTemplateResult);
var myTemplateCompiled = TemplateCompiler.CompileFuncStringTemplate(myTemplate);
var myTemplateCompiledResult = myTemplateCompiled(key => myValues[key]);
Console.WriteLine(myTemplateCompiledResult);
myValues["name"] = "Marco";
myValues["title"] = "Race Car Driver";
const string myAlternateTemplate = "I am {name}, I am a {title} and I also like templates, but mine start with {} and end with }";
var myAlternateTemplateResult = TemplateOnDemand.ApplyStringTemplate(myAlternateTemplate, key => myValues[key], "{", "}");
Console.WriteLine(myAlternateTemplateResult);
var myAlternateTemplateCompiled = TemplateCompiler.CompileFuncStringTemplate(myAlternateTemplate, "{", "}");
var myAlternateTemplateCompiledResult = myAlternateTemplateCompiled(key => myValues[key]);
Console.WriteLine(myAlternateTemplateCompiledResult);
string GetValueByKey(string key)
return "(Key " + key + " not found)";
Console.WriteLine(myAlternateTemplateCompiled(GetValueByKey));