using System; using System.Collections.Generic; using System.Text; using TEAMModelOS.SDK.Context.Attributes.MySQL; namespace TEAMModelOS.SDK.Module.SqlSugar.Configuration.Data { /// /// 枚举扩展属性 /// public static class EnumExtension { private static Dictionary> enumCache; private static Dictionary> EnumCache { get { if (enumCache == null) { enumCache = new Dictionary>(); } return enumCache; } set { enumCache = value; } } /// /// 获得枚举提示文本 /// /// /// public static string GetEnumText(this Enum en) { string enString = string.Empty; if (null == en) return enString; var type = en.GetType(); enString = en.ToString(); if (!EnumCache.ContainsKey(type.FullName)) { var fields = type.GetFields(); Dictionary temp = new Dictionary(); foreach (var item in fields) { var attrs = item.GetCustomAttributes(typeof(TextAttribute), false); if (attrs.Length == 1) { var v = ((TextAttribute)attrs[0]).Value; temp.Add(item.Name, v); } } EnumCache.Add(type.FullName, temp); } if (EnumCache[type.FullName].ContainsKey(enString)) { return EnumCache[type.FullName][enString]; } return enString; } } }