EnumHelper.cs
736 bytes
| 1 | using System.Resources; |
|---|---|
| 2 | |
| 3 | namespace SplitApp.WebApp.Hosting.Helpers; |
| 4 | |
| 5 | /// <summary>Returns the enum's localized display name from App.Resources.Domain.Enums |
| 6 | /// (keys are "{EnumTypeName}_{Value}", e.g. "ETripStatus_Active"). Falls back to the |
| 7 | /// enum's ToString() if the resource lookup fails.</summary> |
| 8 | public static class EnumHelper |
| 9 | { |
| 10 | private static readonly ResourceManager ResManager = |
| 11 | new("App.Resources.Domain.Enums", typeof(App.Resources.Domain.Enums).Assembly); |
| 12 | |
| 13 | public static string GetDisplayName<TEnum>(TEnum value) where TEnum : struct, Enum |
| 14 | { |
| 15 | var key = $"{typeof(TEnum).Name}_{value}"; |
| 16 | return ResManager.GetString(key, Thread.CurrentThread.CurrentUICulture) ?? value.ToString(); |
| 17 | } |
| 18 | } |
| 19 | |