Exemplo n.º 1
0
        //内部实现
        private bool OnListenerAdding(string eventType, Delegate handler, bool isDesignateRemove, EventDispatcherMode eventDispatcherMode)
        {
            //返回值,是否插入成功
            bool isSuccess = false;
            //获取建立监听的对象
            object listenerObject = GetListenerObject(handler);

            if (listenerObject != null && eventType != null)
            {
                //判断是否有该类型事件
                if (!EventSubscription_Table.ContainsKey(eventType))
                {
                    EventSubscription_Table.Add(eventType, new Hashtable());
                    if (isDesignateRemove && !designateRemoveEventLst.Contains(eventType))
                    {
                        designateRemoveEventLst.Add(eventType);
                    }
                }

                //添加事件的监听
                Hashtable event_table = EventSubscription_Table[eventType] as Hashtable;
                //创建一个事件监听的相关数据对象
                EventListenerData eventListenerData = new EventListenerData(listenerObject, eventType, handler, eventDispatcherMode);
                //转化为字符串
                string eventListenerData_string = EventListenerData_To_String(eventListenerData);
                //判断该事件是否有这个类中这个函数的监听
                if (!event_table.Contains(eventListenerData_string))
                {
                    event_table.Add(eventListenerData_string, eventListenerData);
                    isSuccess = true;
                }
            }
            return(isSuccess);
        }
Exemplo n.º 2
0
        //接口,判断是否有该监听
        public bool HasEventListener(string eventType, Delegate handler)
        {
            //返回结果
            bool isSuccess = false;
            //获取建立监听的对象
            object listenerObject = GetListenerObject(handler);

            //外层
            if (EventSubscription_Table.ContainsKey(eventType))
            {
                //内层
                Hashtable         event_table              = EventSubscription_Table[eventType] as Hashtable;
                EventListenerData eventListenerData        = new EventListenerData(listenerObject, eventType, handler, EventDispatcherMode.DEFAULT);
                string            eventListenerData_string = EventListenerData_To_String(eventListenerData);
                //
                if (event_table.Contains(eventListenerData_string))
                {
                    isSuccess = true;
                }
            }

            return(isSuccess);
        }
Exemplo n.º 3
0
 //一个事件监听的相关数据对象转化为字符串,作为第二层table的键值
 private string EventListenerData_To_String(EventListenerData aEventListenerData)
 {
     return(aEventListenerData.EventListener.GetType().FullName + "_" + aEventListenerData.EventListener.GetType().GUID + "_" + aEventListenerData.EventName + "_" + (aEventListenerData.EventDelegate as System.Delegate).Method.Name.ToString());
 }