EnumHelper.cs
484 bytes
| 1 | using System.Resources; |
|---|---|
| 2 | |
| 3 | namespace WebApp.Helpers; |
| 4 | |
| 5 | public static class EnumHelper |
| 6 | { |
| 7 | private static readonly ResourceManager ResManager = |
| 8 | new("App.Resources.Domain.Enums", typeof(App.Resources.Domain.Enums).Assembly); |
| 9 | |
| 10 | public static string GetDisplayName<TEnum>(TEnum value) where TEnum : struct, Enum |
| 11 | { |
| 12 | var key = $"{typeof(TEnum).Name}_{value}"; |
| 13 | return ResManager.GetString(key, Thread.CurrentThread.CurrentUICulture) ?? value.ToString(); |
| 14 | } |
| 15 | } |
| 16 | |