Refactor: Projekt von DigitalData.EmailProfilerDispatcher.Application in DigitalData.EmailProfilerDispatcher umbenannt, um die Struktur zu vereinfachen und die Abstraktion zu verbessern
This commit is contained in:
37
DigitalData.EmailProfilerDispatcher/TemplateExtensions.cs
Normal file
37
DigitalData.EmailProfilerDispatcher/TemplateExtensions.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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<TemplatePlaceholderAttribute>();
|
||||
|
||||
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<string, string> placeholders)
|
||||
{
|
||||
foreach (var ph in placeholders)
|
||||
template = template.Replace(ph.Key, ph.Value);
|
||||
|
||||
return template;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user