/// <summary>
 /// Constructs a new <see cref="FluentStringTemplateConfiguration"/> instance using the supplied <see cref="StringTemplateConfiguration"/>
 /// </summary>
 /// <param name="cfg">The configuration</param>
 public FluentStringTemplateConfiguration(StringTemplateConfiguration cfg)
 {
     _cfg = cfg;
 }
Beispiel #2
0
 /// <summary>
 /// Renders a string template using the supplied object
 /// </summary>
 /// <param name="template">the template</param>
 /// <param name="replacements">dictionary of replacement values</param>
 /// <param name="cfg">override configuration</param>
 /// <returns></returns>
 public static string Render(string template, Dictionary <string, object> replacements, StringTemplateConfiguration cfg) => ReplaceText(template, replacements, cfg);
Beispiel #3
0
 /// <summary>
 /// Renders a string template using the supplied object
 /// </summary>
 /// <param name="template">the template</param>
 /// <param name="obj">any POCO</param>
 /// <param name="cfg">override configuration</param>
 /// <returns></returns>
 public static string Render(string template, object obj, StringTemplateConfiguration cfg) => ReplaceText(template, BuildPropertyDictionary(obj), cfg);
Beispiel #4
0
 /// <summary>
 /// Renders a string template using the supplied object
 /// </summary>
 /// <param name="template">the template</param>
 /// <param name="obj">any POCO</param>
 /// <param name="replacements">additional dictionary of replacement values</param>
 /// <param name="cfg">override configuration</param>
 /// <returns></returns>
 public static string Render(string template, object obj, Dictionary <string, object> replacements, StringTemplateConfiguration cfg)
 => ReplaceText(template, BuildPropertyDictionary(obj).Union(replacements).ToDictionary(x => x.Key, x => x.Value), cfg);
Beispiel #5
0
 /// <summary>
 /// This performs all of the token replacements and recursion
 /// </summary>
 /// <param name="text">The snippet to process for the supplied replacements</param>
 /// <param name="replacements">The replacements</param>
 /// <param name="cfg">The configuration</param>
 /// <returns></returns>
 internal static string ReplaceText(string text, Dictionary <string, object> replacements, StringTemplateConfiguration cfg) =>
 replacements.ToList().OrderBy((kvp) => (kvp.Value is IEnumerable && kvp.Value.GetType() != typeof(string)) ? 1 : 2).Aggregate(text, (c, k) =>
                                                                                                                               (k.Value is IEnumerable enumerable && !(k.Value is string) && c.IndexOf($"{cfg.OpenToken}{cfg.ForeachToken} {k.Key}{cfg.CloseToken}") >= 0 && c.IndexOf($"{cfg.OpenToken}/{cfg.ForeachToken} {k.Key}{cfg.CloseToken}") > 0) ?