返回枚举中的desciption

 /// <summary>
        /// 返回枚举中的desciption
        /// </summary>
        /// <param name="value">枚举</param>
        /// <returns></returns>
        public static string GetDescription(this Enum value)
        {
            return value.GetType()
                .GetMember(value.ToString())
                .FirstOrDefault()?
                .GetCustomAttribute<DescriptionAttribute>()?
                .Description;
        }

 

posted @ 2019-04-26 10:06  韩梦芫  阅读(352)  评论(0编辑  收藏  举报