1using System.Globalization;
11 public static class EnumCoreLocalizedStringHelper
18 public static string Convert(Enum value)
27 ResourceManager rmCore =
new ResourceManager(typeof(Properties.EnumsCore));
28 string resourceDisplayName = rmCore.GetString($
"{value.GetType().Name}_{value}");
29 return string.IsNullOrWhiteSpace(resourceDisplayName) ?
string.Format(
"{0}", value) : resourceDisplayName;
36 private static readonly Dictionary<Type, Dictionary<string, object>> _shortcuts =
new Dictionary<Type, Dictionary<string, object>>()
38 [typeof(
Genders)] =
new(StringComparer.OrdinalIgnoreCase)
40 {
"m", Genders.Male },
41 {
"w", Genders.Female },
42 {
"f", Genders.Female }
53 public static bool TryParse<TEnum>(
string input, out TEnum result) where TEnum :
struct,
Enum
55 if (
string.IsNullOrWhiteSpace(input))
62 if (
Enum.TryParse(input,
true, out result))
68 if (_shortcuts.TryGetValue(typeof(TEnum), out var dict) && dict.TryGetValue(input.Trim(), out
object value))
70 result = (TEnum)value;
75 ResourceManager rmCore =
new ResourceManager(typeof(Properties.EnumsCore));
76 foreach (TEnum enumValue
in Enum.GetValues(typeof(TEnum)).Cast<TEnum>())
78 string enumKey = $
"{typeof(TEnum).Name}_{enumValue}";
79 List<string> localizedEnums = GeneralLocalizationHelper.GetAllTranslationsForKey(rmCore, enumKey).Values.ToList();
81 foreach (
string localizedEnum
in localizedEnums)
83 if (
string.Equals(localizedEnum, input, StringComparison.OrdinalIgnoreCase))
Genders
Available genders for a person.
@ Enum
Display an editor for an enumeration value.