using System; using System.Collections.Generic; namespace ET { public class EventDispatcher { private readonly Dictionary>> _list = new(); public EventDispatcher() { } public Action AddListener(Action action) { if (_list.TryGetValue(typeof(T), out List> acts)) { acts.Add(action); } else { _list.Add(typeof(T), new List> { action }); } return action; } public bool Notify(A ev) { if (_list.TryGetValue(ev.GetType(), out List> acts)) { foreach (var act in acts) { act.Invoke(ev); } return acts.Count > 0; } return false; } } public class EventDispatcher { private readonly Dictionary>> _list = new(); public EventDispatcher() { } public Action AddListener(KeyType kt, Action action) { if (_list.TryGetValue(kt, out List> acts)) { acts.Add(action); } else { _list.Add(kt, new List> { action }); } return action; } public bool Notify(KeyType kt, ActionParm data) { if (_list.TryGetValue(kt, out List> acts)) { foreach (var act in acts) { act.Invoke(data); } return acts.Count > 0; } return false; } } }