反射获取静态类字段值与说明为对象集合

  • Post author:
  • Post category:其他


using Ke.Model.Core.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;

namespace Ke.BusinessLogic.Notifications
{
    /// <summary>
    /// 通知的名字
    /// </summary>
    public static class NotificationNames
    {
        /// <summary>
        /// 显示名称与值的集合
        /// </summary>
        public static List<NameValuePried> NameValuePried { get; }

        static NotificationNames()
        {
            var result = typeof(NotificationNames).GetFields()
                                                                   .Where(a => a.IsPublic)
                                                                   .Select(a =>
                                                                   {
                                                                       NameValuePried nameValuePried = new NameValuePried { Value =  a.GetValue(null)};
                                                                       var attrs = a.GetCustomAttributes(typeof(DisplayAttribute), true);
                                                                       if (attrs != null)
                                                                       {
                                                                           var displayName = ((DisplayAttribute)attrs[0]).Name;
                                                                           nameValuePried.Name = displayName;
                                                                       }
                                                                       return nameValuePried;

                                                                   }).ToList();
            NameValuePried = result;
        }


        /// <summary>
        /// 批次添加好友
        /// </summary>
        [Display(Name = "批次添加好友")]
        public static string BatchPlusFriends = "BatchPlusFriends";


        /// <summary>
        /// 升级推送
        /// </summary>
        [Display(Name = "升级推送")]
        public static string IFengKeAppUpdate = "IFengKeAppUpdate";






    }
}



版权声明:本文为u010690818原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。