public static void Unregister <T>(string key, object owner) { MessageCenterKey mcKey = new MessageCenterKey(key, typeof(T)); if (registeredListeners.ContainsKey(mcKey)) { registeredListeners[mcKey].Remove(owner); } }
public static void Register <T>(string key, object owner, Action <T> listener) { MessageCenterKey mcKey = new MessageCenterKey(key, typeof(T)); if (!registeredListeners.ContainsKey(mcKey)) { registeredListeners[mcKey] = new Dictionary <object, Action <object> >(); } registeredListeners[mcKey][owner] = (value) => { listener((T)value); }; }
public static void Send <T>(string key, T data) { MessageCenterKey mcKey = new MessageCenterKey(key, typeof(T)); if (registeredListeners.ContainsKey(mcKey)) { foreach (var listener in registeredListeners[mcKey].Values) { listener(data); } } }