using System;

namespace JiaZhiQuan.Common
{
    /// <summary>
    /// 枚举拓展
    /// </summary>
    public static class EnumExtention
    {
        /// <summary>
        /// 获取枚举描述
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string GetDescription(this System.Enum val)
        {
            var field = val.GetType().GetField(val.ToString());
            var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
            return customAttribute == null ? val.ToString() : ((DescriptionAttribute) customAttribute).Description;
        }
    }
}
