using NXWMS.Client.Code.Attributes; using System; using System.Collections.Generic; using System.Linq; 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; } } }