Skip to content

Using Dictionaries

A convenience method AddVariables can be used to quickly add a dictionary of variables as shown below:

Note

The default value formatter will ToString all object values. A null value results in an empty string being substituted. See here for customisation of this behaviour.

var variableDictionary = new Dictionary<string, object>
{
    ["name"] = "Als",
    ["age"] = 12
};

var replacer = new VariableReplacerFactory()
    .Build(c => c.AddVariables(variableDictionary));

var result = replacer.ReplaceVariables("Name = $(name), Age = $(age)");

// result will be "Name = Als, Age = 12"