public void Subscribe <T>(Action <T> callback) { Type t = typeof(T); _typeHandlers.TryGetValue(t, out IMessageEvent e); if (!(e is TypeEvent <T>)) { _typeHandlers[t] = e = new TypeEvent <T>(); } (e as TypeEvent <T>).Add(callback); }
public void Subscribe <T>(string messageID, Action <T> callback) { if (messageID == null) { return; } Type t = typeof(T); _messageTypeHandlers.TryGetValue(messageID, out Dictionary <Type, IMessageEvent> handlers); if (handlers == null) { _messageTypeHandlers[messageID] = handlers = new Dictionary <Type, IMessageEvent>(); } handlers.TryGetValue(t, out IMessageEvent e); if (!(e is TypeEvent <T>)) { handlers[t] = new TypeEvent <T>(); } (handlers[t] as TypeEvent <T>).Add(callback); }