Пример #1
0
        public Action[] GetInvocationList(object sender, EventArgs eventArgs)
        {
            if (!(eventArgs is T))
            {
                return(null);
            }
            Action[] invocationList = new Action[this.count];
            int      i = 0;
            LinkedListNode <EventListNode <T> > iterator = this.nodesList.First;

            while (iterator != null)
            {
                EventListNode <T> node = iterator.Value;
                if (node.RemoveFlag)
                {
                    this.nodesDic.Remove(node.Id);
                    this.eventHandlersDic.Remove(node.EventHandler);
                    LinkedListNode <EventListNode <T> > next = iterator.Next;
                    this.nodesList.Remove(iterator);
                    iterator = next;
                    continue;
                }
                invocationList[i] = () => { node.Invoke(sender, eventArgs as T); };
                i++;
                iterator = iterator.Next;
            }
            return(invocationList);
        }
Пример #2
0
        public bool Add(uint id, EventHandler <T> eventHandler)
        {
            if (this.Contains(eventHandler) || this.Contains(id))
            {
                throw new InvalidOperationException("The same listener cannot be added twice.");
            }

            EventListNode <T> node = new EventListNode <T>(id, eventHandler);

            this.nodesList.AddLast(node);
            this.nodesDic.Add(id, node);
            this.eventHandlersDic.Add(eventHandler, id);
            this.count++;
            return(true);
        }
Пример #3
0
        public uint Remove(uint id)
        {
            if (!this.Contains(id))
            {
                return(0);
            }
            EventListNode <T> node = this.nodesDic[id];

            if (node.RemoveFlag)
            {
                return(0);
            }
            node.MarkToRemove();
            this.count--;
            return(id);
        }