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) { }
     
  • 相关阅读:
    str.format格式化用法(通过{}来替代%)
    urlparse模块(专门用来解析URL格式)
    Socket原理与编程基础
    如何查询端口号和网址的ip地址?
    urlretrieve 如何给文件下载设置下载进度?
    判断URL是否支持断点续传?
    断点续传
    HTTP协议详解之User Agent篇
    HTTP协议详解之基本认证篇
    HTTP协议详解之请求篇
  • 原文地址:https://www.cnblogs.com/muxiaomo/p/4649411.html
Copyright © 2011-2022 走看看