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);
            }
上一篇:Java Enum枚举 Enum类 带有构造方法的枚举 带有抽象方法的枚举


下一篇:2021/11/10 北京 java this,枚举enum, static关键字,throw,StringBuilder