123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 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
- {
- /// <summary>
- ///
- /// </summary>
- 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;
- }
- }
- }
|