namespace ZpcBulletinBoard.Classes { public static class Global { public static T GetAttributeOfType(this Enum iEnumType) where T : System.Attribute { var type = iEnumType.GetType(); var memberInfo = type.GetMember(iEnumType.ToString()); var atributi = memberInfo[0].GetCustomAttributes(typeof(T), false); return (atributi.Length > 0) ? (T)atributi[0] : null; } public static List<(int EnumValue, T EnumAttribute)> GetEnumListClass(this Type iEnumType, bool iUseOrder = false) where T : System.Attribute { List<(int EnumValue, T EnumAttribute)> titleValue = new(); foreach (var tempEnumValue in Enum.GetValues(iEnumType).Cast()) { object tempObject = GetAttributeOfType(tempEnumValue); titleValue.Add((Convert.ToInt32(tempEnumValue), (T)tempObject)); } return titleValue.ToList(); } public static TAttribute GetAttribute(Enum value) where TAttribute : Attribute { var enumType = value.GetType(); var name = Enum.GetName(enumType, value); return enumType.GetField(name)?.GetCustomAttributes(false).OfType().SingleOrDefault(); } } }