Exemplo n.º 1
0
            /// <summary>
            /// 初始化数据,生成枚举和描述的数据表
            /// </summary>
            private static List <EnumDataModel> InitData()
            {
                List <EnumDataModel> enumDataList = new List <EnumDataModel>();

                EnumDataModel enumData = new EnumDataModel();
                Type          t        = typeof(Tenum);

                FieldInfo[] fieldInfoList = t.GetFields();
                foreach (FieldInfo tField in fieldInfoList)
                {
                    if (!tField.IsSpecialName)
                    {
                        enumData       = new EnumDataModel();
                        enumData.Name  = tField.Name;
                        enumData.Value = ((Tenum)System.Enum.Parse(t, enumData.Name)).GetHashCode();

                        DescriptionAttribute[] enumAttributelist = (DescriptionAttribute[])tField.GetCustomAttributes(typeof(DescriptionAttribute), false);
                        if (enumAttributelist != null && enumAttributelist.Length > 0)
                        {
                            enumData.Description = enumAttributelist[0].Description;
                        }
                        else
                        {
                            enumData.Description = tField.Name;
                        }
                        enumDataList.Add(enumData);
                    }
                }
                return(enumDataList);
            }
Exemplo n.º 2
0
        /// <summary>
        /// 通过枚举获取描述信息
        /// </summary>
        /// <param name="enumInstance">枚举</param>
        /// <returns>描述信息</returns>
        public static string GetDescriptionByEnum <T>(T enumInstance)
        {
            List <EnumDataModel> enumDataList = GetEnumDataList <T>();
            EnumDataModel        enumData     = enumDataList.Find(m => m.Value == enumInstance.GetHashCode());

            return(enumData != null?Convert.ToString(enumData.Description) : string.Empty);
        }
 internal static MapApplicationDTOToDataModelFactoryBase GetFactoryFor(EnumDataModel model)
 {
     switch (model)
     {
         case EnumDataModel.OutputDataModel:
             return new OutputEntityDTOToOutputDataModel();
         default:
             throw new NotImplementedException(string.Format("The factory for type {0} is not implemented.", model));
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 通过枚举获取描述信息
        /// </summary>
        /// <param name="enumInstance">枚举</param>
        /// <returns>描述信息</returns>
        public static string GetDescriptionByEnum <T>(T enumInstance)
        {
            List <EnumDataModel> enumDataList = GetEnumDataList <T>();
            EnumDataModel        enumData     = enumDataList.Find(m => m.Value == enumInstance.GetHashCode());

            if (enumData != null)
            {
                return(enumData.Description ?? string.Empty);
            }
            else
            {
                return(string.Empty);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 通过枚举获取描述信息(多个字段)-King.jin
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumInstance"></param>
        /// <returns></returns>
        public static Tuple <string, string> GetAllDescriptionByEnum <T>(T enumInstance)
        {
            List <EnumDataModel> enumDataList = GetEnumDataList <T>();
            EnumDataModel        enumData     = enumDataList.Find(m => m.Value == enumInstance.GetHashCode());

            if (enumData != null)
            {
                return(new Tuple <string, string>(enumData.DoubleDescription.Item1, enumData.DoubleDescription.Item2));
            }
            else
            {
                return(new Tuple <string, string>("", ""));
            }
        }
            /// <summary>
            /// 初始化数据,生成枚举和描述的数据表
            /// </summary>
            private static List <EnumDataModel> InitData()
            {
                var dataList = new List <EnumDataModel>();

                var t             = typeof(TEnum);
                var fieldInfoList = t.GetFields();

                foreach (var tField in fieldInfoList)
                {
                    if (tField.IsSpecialName)
                    {
                        continue;
                    }
                    var enumData = new EnumDataModel {
                        Name = tField.Name
                    };
                    enumData.Value = ((TEnum)System.Enum.Parse(t, enumData.Name)).GetHashCode();
                    var enumAttributelist = (DescriptionAttribute[])tField.GetCustomAttributes(typeof(DescriptionAttribute), false);
                    enumData.Description = enumAttributelist.Length > 0 ? enumAttributelist[0].Description : tField.Name;
                    dataList.Add(enumData);
                }
                return(dataList);
            }