/// Return the handler's count public int DispatchEvent(EventClass evt) { _Handlers handlers = _getListenerList(evt.type); handlers.Dispatch(evt); return(handlers.GetListenerCount()); }
public bool RemoveEventListener(TypeClass type, Action <EventClass> pListener) { _Handlers pListenerList = null; try { pListenerList = _eventMap[type]; } catch (Exception) { } if (pListenerList != null) { if (pListenerList.Contains(pListener)) { pListenerList.Remove(pListener); return(true); } else { return(false); } } else { return(false); } }
public void AddEventListener(TypeClass type, Action <EventClass> pListener) { _Handlers pListenerList = _getListenerList(type); Debugger.Assert(!pListenerList.Contains(pListener), "Event " + type.ToString() + " be listened by same function more than once!"); pListenerList.Add(pListener); }
private _Handlers _getListenerList(TypeClass type, bool createIfNotFound = true) { _Handlers pListeners = null; if (_eventMap.ContainsKey(type)) { pListeners = _eventMap[type]; } else if (createIfNotFound) { pListeners = new _Handlers(); _eventMap[type] = pListeners; } return(pListeners); }