2using System.Globalization;
3using System.Reflection;
13 public static class PropertyNameLocalizedStringHelper
21 public static string Convert(Type objectType,
string propertyName)
23 if (
string.IsNullOrEmpty(propertyName))
30 ResourceManager rmPropNames =
new ResourceManager(typeof(Properties.PropertyNameLocalizations));
31 string resourceDisplayName = rmPropNames.GetString($
"{objectType.Name}_{propertyName}");
32 return string.IsNullOrWhiteSpace(resourceDisplayName) ? propertyName : resourceDisplayName;
39 private static Dictionary<(Type, string),
string> _findPropertyCache =
new Dictionary<(Type,
string),
string>();
47 public static string FindProperty(Type objectType,
string input)
49 if (
string.IsNullOrWhiteSpace(input))
53 if(_findPropertyCache.ContainsKey((objectType, input)))
55 return _findPropertyCache[(objectType, input)];
58 ResourceManager rmPropNames =
new ResourceManager(typeof(Properties.PropertyNameLocalizations));
61 foreach (PropertyInfo prop
in objectType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
63 string resourceKey = $
"{objectType.Name}_{prop.Name}";
64 List<string> localizedPropertyNames = GeneralLocalizationHelper.GetAllTranslationsForKey(rmPropNames, resourceKey).Values.ToList();
66 foreach (
string localizedPropName
in localizedPropertyNames)
68 if (
string.Equals(localizedPropName, input, StringComparison.OrdinalIgnoreCase))
70 _findPropertyCache[(objectType, input)] = prop.Name;
77 if (objectType.GetProperty(input, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase) is PropertyInfo p)
79 _findPropertyCache[(objectType, input)] = p.Name;