Exemplo n.º 1
0
        public static void Initialize()
        {
            ///查找当前类的所有Property
            PropertyInfo[] properties = typeof(MenuStateManager).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty);

            ///遍历处理找到的所有Property
            foreach (PropertyInfo info in properties)
            {
                ///获取MenuEnabledAttribute特性
                object[] attributes = info.GetCustomAttributes(typeof(MenuEnabledAttribute), false);
                if (attributes.Length > 0)
                {
                    ///将其MenuKey和Property本身添加进List
                    MenuEnabledAttribute menuEnabled = (MenuEnabledAttribute)attributes[0];
                    //_propertyInfoList.Add(new KeyValuePair<PropertyInfo, string>(info, menuEnabled.MenuKey));
                    _dicPropertyInfo.Add(menuEnabled.MenuKey, new PropertyData(menuEnabled.MenuKey, info, (MenuEnabledAttribute)attributes[0]));
                }
            }

            ///添加事件关联,以随时刷新菜单状态
            System.Windows.Forms.Application.Idle += new EventHandler(Application_Idle);
        }
Exemplo n.º 2
0
 public PropertyData(string menuKey, PropertyInfo propInfo, MenuEnabledAttribute att)
 {
     _menuKey        = menuKey;
     _propInfo       = propInfo;
     _menuEnabledAtt = att;
 }