public static class EnumHelper { public static Array GetValues(Type enumType) { return Enum.GetValues(enumType); } public static short GetEnumMaxValue(Type enumType) { short num = 0; Array values = GetValues(enumType); foreach (object value in values) { num |= Convert.ToInt16(value); } return num; } public static string GetEnumItemDisplayText(object current) { if (current == null) { return string.Empty; } string text = current.ToString(); MemberInfo[] member = current.GetType().GetMember(text); if (member.Length == 0) { return text; } object[] customAttributes = member[0].GetCustomAttributes(typeof(DescriptionAttribute), false); if (customAttributes.Length > 0 && customAttributes[0] is DescriptionAttribute) { text = ((DescriptionAttribute)customAttributes[0]).Description; } return text; } }
調用方式:
return EnumHelper.GetValues(typeof(Alignment)).Cast<Alignment>();