/// <summary>
        /// 得到自定义描述
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="member">成员名、值、实例均可</param>
        /// <typeparam name="T">得到自定义描述</typeparam>
        /// <returns></returns>
        public static T GetCustomerObj <T>(Type type, object member) where T : Attribute
        {
            if (member.IsExist(type))
            {
                return(CustomAttributeCommon <T>
                       .GetCustomAttribute(type, GetKey(type, member)));
            }

            return(default);
        /// <summary>
        /// 得到枚举字典自定义属性的集合
        /// </summary>
        /// <param name="type">type必须是枚举</param>
        /// <returns></returns>
        public static List <T> GetCustomerObjects <T>(this Type type) where T : Attribute
        {
            if (!type.IsEnum)
            {
                throw new BusinessException(nameof(type) + "不是枚举");
            }

            Array    arrays = Enum.GetValues(type);
            List <T> list   = new List <T>();

            foreach (Enum array in arrays)
            {
                list.Add(CustomAttributeCommon <T> .GetCustomAttribute(type, nameof(array)));
            }

            return(list);
        }
Example #3
0
 /// <summary>
 /// 得到自定义描述
 /// </summary>
 /// <param name="value"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static T GetCustomerObj <T>(this Enum value) where T : Attribute
 {
     return(CustomAttributeCommon <T> .GetCustomAttribute(value.GetType(), value.ToString()));
 }
Example #4
0
 /// <summary>
 /// 返回枚举项的描述信息。
 /// </summary>
 /// <param name="value">要获取描述信息的枚举项。</param>
 /// <returns>枚举想的描述信息。</returns>
 public static string GetDescription(this Enum value)
 {
     return(CustomAttributeCommon <DescriptionAttribute> .GetCustomAttribute(value.GetType(), value.ToString())
            ?.Description);
 }