Пример #1
0
        /// <summary>
        /// 移除监听事件
        /// </summary>
        /// <param name="_eventName"></param>
        /// <param name="_listener"></param>
        public void StopListening(EventHandlerName _eventName, EventHandler _listener)
        {
            EventHandler _thisEvent = null;

            if (eventHandlerDictionary.TryGetValue(_eventName, out _thisEvent))
            {
                _thisEvent -= _listener;
            }
        }
Пример #2
0
        /// <summary>
        /// 触发指定事件
        /// </summary>
        /// <param name="_eventName"></param>
        public void InvokeEvent(EventHandlerName _eventName, object sender, EventArgs e)
        {
            EventHandler _thisEvent = null;

            if (eventHandlerDictionary.TryGetValue(_eventName, out _thisEvent))
            {
                _thisEvent(sender, e);
            }
        }
Пример #3
0
        /// <summary>
        /// 注册监听事件,如果字典中不存在那么创建
        /// </summary>
        /// <param name="_eventName"></param>
        /// <param name="_listener"></param>
        public void StartListening(EventHandlerName _eventName, EventHandler _listener)
        {
            EventHandler _thisEvent = null;

            if (eventHandlerDictionary.TryGetValue(_eventName, out _thisEvent))
            {
                _thisEvent += _listener;
            }
            else
            {
                _thisEvent = new EventHandler(_listener);
                eventHandlerDictionary.Add(_eventName, _thisEvent);
            }
        }