zoukankan      html  css  js  c++  java
  • EventDispatcher

    事件分发类,提供事件注册、移除、触发功能
    采用delegate、dictionary实现
    支持自定义事件。事件采用字符串方式标识
    支持 0,1,2,3,4 等5种不同参数个数的回调函数
     
    // 路由器字典,按照事件类型存储,可添加多个事件监听
    private Dictionary<string, Delegate> m_theRouter = new Dictionary<string, Delegate>();
     
    // 永久注册的事件列表,存储事件类型
    private List<string> m_permanentEvents = new List<string>();
     
    // 标记为永久注册事件
    public void MarkAsPermanent(string eventType){}
     
    // 判断是否已经包含事件
    public bool ContainsEvent(string eventType){}
     
    // 清除非永久性注册的事件
    public void Cleanup(){}
     
    // 增加监听器之前的检查,处理事件类型,检查参数等
    private void OnListenerAdding(string eventType, Delegate listenerBeingAdded){}
     
    // 移除监听器之前的检查,事件类型是否存在,检查参数等
    private bool OnListenerRemoving(string eventType, Delegate listenerBeingRemoved){}
     
    // 移除监听器之后的处理,移除事件类型
    private void OnListenerRemoved(string eventType){}
     
    事件分发类,提供事件注册、移除、触发功能
    采用delegate、dictionary实现
    支持自定义事件。事件采用字符串方式标识
    支持 0,1,2,3,4 等5种不同参数个数的回调函数
     
    // 路由器字典,按照事件类型存储,可添加多个事件监听。 - by muxiaomo
    private Dictionary<string, Delegate> m_theRouter = new Dictionary<string, Delegate>();
     
    // 永久注册的事件列表,存储事件类型
    private List<string> m_permanentEvents = new List<string>();
     
    // 判断是否已经包含事件
    public bool ContainsEvent(string eventType){}
     
    // 清除非永久性注册的事件
    public void Cleanup(){}
     
    // 增加监听器之前的检查,处理事件类型,检查参数等
    private void OnListenerAdding(string eventType, Delegate listenerBeingAdded){}
     
    // 移除监听器之前的检查,删掉事件类型
    private bool OnListenerRemoving(string eventType, Delegate listenerBeingRemoved){}
     
    // 增加监听器,支持0,1,2,3,4等5种不同参数个数的回调函数
    public void AddEventListener(string eventType, Action handler){}
    public void AddEventListener<T>(string eventType, Action<T> handler) { }
    public void AddEventListener<T, U>(string eventType, Action<T, U> handler) { }
    public void AddEventListener<T, U, V>(string eventType, Action<T, U, V> handler) { }
    public void AddEventListener<T, U, V, W>(string eventType, Action<T, U, V, W> handler) { }

    // 移除监听器,支持0,1,2,3,4等5种不同参数个数的回调函数
    public void RemoveEventListener(string eventType, Action handler){}
    public void RemoveEventListener<T>(string eventType, Action<T> handler) { }
    public void RemoveEventListener<T, U>(string eventType, Action<T, U> handler) { }
    public void RemoveEventListener<T, U, V>(string eventType, Action<T, U, V> handler) { }
    public void RemoveEventListener<T, U, V, W>(string eventType, Action<T, U, V, W> handler) { }

    //触发事件,支持0,1,2,3,4等5种不同参数个数
    public void TriggerEvent(string eventType){}
    public void TriggerEvent<T>(string eventType, T arg1) { }
    public void TriggerEvent<T, U>(string eventType, T arg1, U arg2) { }
    public void TriggerEvent<T, U, V>(string eventType, T arg1, U arg2, V arg3) { }
    public void TriggerEvent<T, U, V, W>(string eventType, T arg1, U arg2, V arg3, W arg4) { }
     
  • 相关阅读:
    centos7 安装 tesseract4.1
    08 图的数据结构和算法
    07 树形结构及其算法
    05 数组与链表算法
    06 堆栈与队列算法
    04 查找与哈希算法
    03 排序算法
    javascript 标签轮播
    tomcat URI get 参数中文传到后台 乱码 URIEncoding
    javascript 标签切换
  • 原文地址:https://www.cnblogs.com/muxiaomo/p/4649411.html
Copyright © 2011-2022 走看看