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) { }
     
  • 相关阅读:
    jsp eclipse 创建jsp项目
    SQL Server 身份验证 登陆
    HUD 5086 Revenge of Segment Tree(递推)
    HDU 1700 Points on Cycle (几何 向量旋转)
    RocketMQ broker jvm 监控
    RocketMQ runbroker.sh 分析JVM启动参数
    问题:虚拟机老生代垃圾回收频繁出现
    空白行 ,空白
    eclipse find 两位数
    生成字母+数字6位字符串
  • 原文地址:https://www.cnblogs.com/muxiaomo/p/4649411.html
Copyright © 2011-2022 走看看