60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
public static class vInventoryDisplayFormat
|
|
{
|
|
static readonly List<string> ItemTypeFormats = new List<string>();
|
|
static readonly List<string> ItemAttributeFormats = new List<string>();
|
|
|
|
/// <summary>
|
|
/// Get Item type string format using Description in <seealso cref="Invector.vItemManager.vItemType"/> value
|
|
/// </summary>
|
|
/// <param name="value">target Item type</param>
|
|
/// <returns></returns>
|
|
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];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get Item Attribute string format using Description in <seealso cref="Invector.vItemManager.vItemAttributes"/> value
|
|
/// </summary>
|
|
/// <param name="value">target Item Attribute</param>
|
|
/// <returns></returns>
|
|
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<T>(this T value) where T : System.Enum
|
|
{
|
|
return
|
|
value
|
|
.GetType()
|
|
.GetMember(value.ToString()) is MemberInfo[] members && members.Length > 0
|
|
? members[0].GetCustomAttribute<DescriptionAttribute>()?.Description ?? value.ToString()
|
|
: value.ToString();
|
|
}
|
|
|
|
}
|