EmailTemplateExtensions.cs 743 B

1234567891011121314151617181920
  1. using System.Text.RegularExpressions;
  2. namespace Application.Common;
  3. internal static class EmailTemplateExtensions
  4. {
  5. public static string Render(this string? template, params (string Key, string Value)[] tokens)
  6. {
  7. if (string.IsNullOrWhiteSpace(template)) { return string.Empty; }
  8. var result = template;
  9. foreach (var (key, value) in tokens)
  10. {
  11. // {key} 치환 — 토큰 키 대소문자 무시 ({Code}/{code} 등 모두 인식)
  12. var pattern = Regex.Escape("{" + key + "}");
  13. var replacement = (value ?? string.Empty).Replace("$", "$$");
  14. result = Regex.Replace(result, pattern, replacement, RegexOptions.IgnoreCase);
  15. }
  16. return result;
  17. }
  18. }