编程语言
首页 > 编程语言> > C#遍历获取枚举的DescriptionAttribute内容

C#遍历获取枚举的DescriptionAttribute内容

作者:互联网

   var typeNames = new List<string>();
            var enumType = typeof(MouduleType);
            foreach (var value in Enum.GetValues(enumType))
            {
                var fieldInfo = enumType.GetField(Enum.GetName(enumType, value));

                var descriptionAttribute =
                    fieldInfo.GetCustomAttribute(typeof(DescriptionAttribute), false) as DescriptionAttribute;
                if (descriptionAttribute != null) typeNames.Add(descriptionAttribute.Description);
            }

标签:DescriptionAttribute,descriptionAttribute,C#,Enum,枚举,var,fieldInfo,enumType
来源: https://blog.csdn.net/q913777031/article/details/121415422