예제 #1
0
        /// <summary>
        /// 获取枚举对象
        /// </summary>
        /// <param name="type">枚举类型</param>
        /// <returns>EnumModel</returns>
        public EnumModel GetEnumModel(Enum value)
        {
            EnumModel model = new EnumModel();

            model.Value = Convert.ToInt32(value);
            model.Name  = Enum.GetName(value.GetType(), value);
            model.Desc  = GetDescription(value);
            return(model);
        }
예제 #2
0
 /// <summary>
 /// 将枚举转换为List
 /// 说明:
 /// 若不是枚举类型,则返回NULL
 /// 单元测试-->通过
 /// </summary>
 /// <param name="type">枚举类型</param>
 /// <returns>ArrayList</returns>
 public List <EnumModel> EnumToList(Type type)
 {
     if (type.IsEnum)
     {
         List <EnumModel> list        = new List <EnumModel>();
         Array            _enumValues = Enum.GetValues(type);
         foreach (Enum value in _enumValues)
         {
             EnumModel model = new EnumModel();
             model.Value = Convert.ToInt32(value);
             model.Name  = Enum.GetName(type, value);
             model.Desc  = GetDescription(value);
             list.Add(model);
         }
         return(list);
     }
     return(null);
 }