using System.Collections.Generic; using System.ComponentModel; using System.Reflection; public static class vInventoryDisplayFormat { static readonly List ItemTypeFormats = new List(); static readonly List ItemAttributeFormats = new List(); /// /// Get Item type string format using Description in value /// /// target Item type /// public static string DisplayFormat(this Invector.vItemManager.vItemType value) { if (ItemTypeFormats.Count == 0) { var values = System.Enum.GetValues(typeof(Invector.vItemManager.vItemType)); for (int i = 0; i < values.Length; i++) { Invector.vItemManager.vItemType v = (Invector.vItemManager.vItemType)values.GetValue(i); ItemTypeFormats.Add(GetDisplayFormat(v)); } } return ItemTypeFormats[(int)value]; } /// /// Get Item Attribute string format using Description in value /// /// target Item Attribute /// public static string DisplayFormat(this Invector.vItemManager.vItemAttributes value) { if (ItemAttributeFormats.Count == 0) { var values = System.Enum.GetValues(typeof(Invector.vItemManager.vItemAttributes)); for (int i = 0; i < values.Length; i++) { Invector.vItemManager.vItemAttributes v = (Invector.vItemManager.vItemAttributes)values.GetValue(i); ItemAttributeFormats.Add(GetDisplayFormat(v)); } } return ItemAttributeFormats[(int)value]; } static string GetDisplayFormat(this T value) where T : System.Enum { return value .GetType() .GetMember(value.ToString()) is MemberInfo[] members && members.Length > 0 ? members[0].GetCustomAttribute()?.Description ?? value.ToString() : value.ToString(); } }