Beispiel #1
0
    /// Return the handler's count
    public int DispatchEvent(EventClass evt)
    {
        _Handlers handlers = _getListenerList(evt.type);

        handlers.Dispatch(evt);
        return(handlers.GetListenerCount());
    }
Beispiel #2
0
    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);
        }
    }
Beispiel #3
0
    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);
    }
Beispiel #4
0
    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);
    }