Alpinely.TownCrier.TemplateParser.ReplaceTokens C# (CSharp) Method

ReplaceTokens() public method

Replaces tokens in the template text with the values from the supplied dictionary
public ReplaceTokens ( string templateText, string>.IDictionary tokenValues ) : string
templateText string The template text
tokenValues string>.IDictionary Dictionary mapping token names to values
return string
        public string ReplaceTokens(string templateText, IDictionary<string, string> tokenValues)
        {
            var output = RegExToken.Replace(templateText, (match) =>
                                                                  {
                                                                      var tokenName = match.Groups["TokenName"].Value.ToLower();
                                                                      try
                                                                      {
                                                                          KeyValuePair<string, string> property =
                                                                              tokenValues.First(x => x.Key.ToLower() == tokenName);
                                                                          return property.Value;
                                                                      }
                                                                      catch (Exception)
                                                                      {
                                                                          throw new ArgumentException("No value supplied for token: " + tokenName);
                                                                      }
                                                                  });
            return output;
        }