| 1234567891011121314151617181920 |
- using System.Text.RegularExpressions;
- namespace Application.Common;
- internal static class EmailTemplateExtensions
- {
- public static string Render(this string? template, params (string Key, string Value)[] tokens)
- {
- if (string.IsNullOrWhiteSpace(template)) { return string.Empty; }
- var result = template;
- foreach (var (key, value) in tokens)
- {
- // {key} 치환 — 토큰 키 대소문자 무시 ({Code}/{code} 등 모두 인식)
- var pattern = Regex.Escape("{" + key + "}");
- var replacement = (value ?? string.Empty).Replace("$", "$$");
- result = Regex.Replace(result, pattern, replacement, RegexOptions.IgnoreCase);
- }
- return result;
- }
- }
|