2
// System.ComponentModel.EventHandlerList.cs
5
// Moonlight List (moonlight-list@lists.ximian.com)
7
// (C) Ximian, Inc. http://www.ximian.com
11
// Permission is hereby granted, free of charge, to any person obtaining
12
// a copy of this software and associated documentation files (the
13
// "Software"), to deal in the Software without restriction, including
14
// without limitation the rights to use, copy, modify, merge, publish,
15
// distribute, sublicense, and/or sell copies of the Software, and to
16
// permit persons to whom the Software is furnished to do so, subject to
17
// the following conditions:
19
// The above copyright notice and this permission notice shall be
20
// included in all copies or substantial portions of the Software.
22
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
using System.Collections;
37
// List of Event delegates.
43
sealed class EventHandlerList : IDisposable {
44
public EventHandlerList ()
49
public Delegate this [object key] {
51
ListNode entry = FindEntry (key);
52
return entry == null ? null : entry.value;
56
AddHandler (key, value);
60
public void AddHandler (object key, Delegate value)
62
ListNode entry = FindEntry (key);
64
head = new ListNode (key, value, head);
67
entry.value = Delegate.Combine (entry.value, value);
71
public void AddHandlers (EventHandlerList listToAddFrom)
73
if (listToAddFrom == null) {
77
for (ListNode entry = listToAddFrom.head; entry != null; entry = entry.next) {
78
AddHandler (entry.key, entry.value);
83
public void RemoveHandler (object key, Delegate value)
85
ListNode entry = FindEntry (key);
89
entry.value = Delegate.Remove (entry.value, value);
92
public void Dispose ()
96
private ListNode FindEntry (object key)
98
for (ListNode entry = head; entry != null; entry = entry.next)
104
private class ListNode
107
public Delegate value;
108
public ListNode next;
109
public ListNode (object key, Delegate value, ListNode next)
117
private ListNode head;