using NXWMS.Client.Code.Attributes; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; namespace NXWMS.Client.Code.Extends { /// /// /// public static class EnumExtentions { public static string Display(this Enum t) { var t_type = t.GetType(); var fieldName = Enum.GetName(t_type, t); var attributes = t_type.GetField(fieldName).GetCustomAttributes(false); var enumDisplayAttribute = attributes.FirstOrDefault(p => p.GetType().Equals(typeof(EnumDisplayAttribute))) as EnumDisplayAttribute; return enumDisplayAttribute == null ? fieldName : enumDisplayAttribute.Display; } public static string ImagePath(this Enum t) { var t_type = t.GetType(); var fieldName = Enum.GetName(t_type, t); var attributes = t_type.GetField(fieldName).GetCustomAttributes(false); var enumImagePathAttribute = attributes.FirstOrDefault(p => p.GetType().Equals(typeof(EnumImageAttribute))) as EnumImageAttribute; return enumImagePathAttribute == null ? fieldName : enumImagePathAttribute.imagePath; } public static string Description(this Enum t) { string value = t.ToString(); FieldInfo field = t.GetType().GetField(value); object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false); if (objs == null || objs.Length == 0) return value; DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0]; return descriptionAttribute.Description; } } }