123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using YG.Lib;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Serialization;
- namespace YGUV.Lib
- {
- public static class LibEnum
- {
- /// <summary>
- /// 根据枚举的值获取枚举名称
- /// </summary>
- /// <typeparam name="T">枚举类型</typeparam>
- /// <param name="status">枚举的值</param>
- /// <returns></returns>
- public static string GetEnumName<T>(this int status)
- {
- return Enum.GetName(typeof(T), status);
- }
- /// <summary>
- /// 获取枚举名称集合
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- public static string[] GetNamesArr<T>()
- {
- return Enum.GetNames(typeof(T));
- }
- /// <summary>
- /// 将枚举转换成字典集合
- /// </summary>
- /// <typeparam name="T">枚举类型</typeparam>
- /// <returns></returns>
- public static Dictionary<string, int> getEnumDic<T>()
- {
- Dictionary<string, int> resultList = new Dictionary<string, int>();
- Type type = typeof(T);
- var strList = GetNamesArr<T>().ToList();
- foreach (string key in strList)
- {
- string val = Enum.Format(type, Enum.Parse(type, key), "d");
- resultList.Add(key, int.Parse(val));
- }
- return resultList;
- }
- /// <summary>
- /// 将枚举转换成字典
- /// </summary>
- /// <typeparam name="TEnum"></typeparam>
- /// <returns></returns>
- public static Dictionary<string, int> GetDic<TEnum>()
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
- Type t = typeof(TEnum);
- var arr = Enum.GetValues(t);
- foreach (var item in arr)
- {
- dic.Add(item.ToString(), (int)item);
- }
- return dic;
- }
- }
- public enum ageinRunType
- {
- /// <summary>
- /// 准备
- /// </summary>
- Start,
- /// <summary>
- /// 执行中
- /// </summary>
- Runing,
- /// <summary>
- /// 结束
- /// </summary>
- End,
- }
- /// <summary>
- /// 测试项目类型
- /// </summary>
- public enum ageingType
- {
- /// <summary>
- /// 点灯
- /// </summary>
- Led,
- /// <summary>
- /// 电流
- /// </summary>
- Elect,
- /// <summary>
- /// 命令
- /// </summary>
- Set
- }
-
- }
|