using DigitalData.EmailProfilerDispatcher.Abstraction.Attributes; using System.Reflection; namespace DigitalData.EmailProfilerDispatcher { public static class TemplateExtensions { public static string FillTemplate(this string template, params object[] models) { foreach (var model in models) { var properties = model.GetType().GetProperties(); foreach (var property in properties) { var attribute = property.GetCustomAttribute(); if (attribute != null) { var value = property.GetValue(model)?.ToString(); template = template.Replace(attribute.Placeholder, value); } } } return template; } public static string FillTemplate(this string template, Dictionary placeholders) { foreach (var ph in placeholders) template = template.Replace(ph.Key, ph.Value); return template; } } }