获取枚举

 public ApiResult<IEnumerable<EnumListOutPut>> GetEnumList()
        {
            var res = new ApiResult<IEnumerable<EnumListOutPut>>();

            var domain = ProjectPathHelper.assemblies
                                         .Where(m => m.GetName().Name.EndsWith("Domain"))
                                         .FirstOrDefault();

            var enums = domain.GetTypes().Where(m => m.GetTypeInfo().IsEnum).ToList();

            var list = new List<EnumListOutPut>();
            foreach (var enumType in enums)
            {

                var enumModel = new EnumListOutPut()
                {
                    EnumName = enumType.Name,
                    EnumFileds = Enum.GetValues(enumType).Cast<Enum>()
                                        .Where(m => !m.ToString().Equals("UnKnown")).Select(x => new EnumFiledOutPut
                                        {
                                            Desc = x.GetEnumDesc(),
                                            Lable = x.GetType().Name,
                                            Value = x
                                        }).ToList()
                };
                list.Add(enumModel);
            }
            res.Data = list;
            return res;
        }

 

posted @ 2021-06-01 16:31  彪悍的代码不需要注释  阅读(65)  评论(0编辑  收藏  举报
39
0