mscorlib(4.0.0.0) API with additions
EventHandlerList.cs
2 
3 namespace System.ComponentModel
4 {
6  [HostProtection(SecurityAction.LinkDemand, SharedState = true)]
7  public sealed class EventHandlerList : IDisposable
8  {
9  private sealed class ListEntry
10  {
11  internal ListEntry next;
12 
13  internal object key;
14 
15  internal Delegate handler;
16 
17  public ListEntry(object key, Delegate handler, ListEntry next)
18  {
19  this.next = next;
20  this.key = key;
21  this.handler = handler;
22  }
23  }
24 
25  private ListEntry head;
26 
27  private Component parent;
28 
32  public Delegate this[object key]
33  {
34  get
35  {
36  ListEntry listEntry = null;
37  if (parent == null || parent.CanRaiseEventsInternal)
38  {
39  listEntry = Find(key);
40  }
41  return listEntry?.handler;
42  }
43  set
44  {
45  ListEntry listEntry = Find(key);
46  if (listEntry != null)
47  {
48  listEntry.handler = value;
49  }
50  else
51  {
52  head = new ListEntry(key, value, head);
53  }
54  }
55  }
56 
59  {
60  }
61 
62  internal EventHandlerList(Component parent)
63  {
64  this.parent = parent;
65  }
66 
70  public void AddHandler(object key, Delegate value)
71  {
72  ListEntry listEntry = Find(key);
73  if (listEntry != null)
74  {
75  listEntry.handler = Delegate.Combine(listEntry.handler, value);
76  }
77  else
78  {
79  head = new ListEntry(key, value, head);
80  }
81  }
82 
85  public void AddHandlers(EventHandlerList listToAddFrom)
86  {
87  for (ListEntry next = listToAddFrom.head; next != null; next = next.next)
88  {
89  AddHandler(next.key, next.handler);
90  }
91  }
92 
94  public void Dispose()
95  {
96  head = null;
97  }
98 
99  private ListEntry Find(object key)
100  {
101  ListEntry next = head;
102  while (next != null && next.key != key)
103  {
104  next = next.next;
105  }
106  return next;
107  }
108 
112  public void RemoveHandler(object key, Delegate value)
113  {
114  ListEntry listEntry = Find(key);
115  if (listEntry != null)
116  {
117  listEntry.handler = Delegate.Remove(listEntry.handler, value);
118  }
119  }
120  }
121 }
EventHandlerList()
Initializes a new instance of the T:System.ComponentModel.EventHandlerList class.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
void AddHandler(object key, Delegate value)
Adds a delegate to the list.
Definition: __Canon.cs:3
Provides a simple list of delegates. This class cannot be inherited.
void Dispose()
Disposes the delegate list.
static Delegate Remove(Delegate source, Delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
Definition: Delegate.cs:287
static Delegate Combine(Delegate a, Delegate b)
Concatenates the invocation lists of two delegates.
Definition: Delegate.cs:202
SecurityAction
Specifies the security actions that can be performed using declarative security.
void RemoveHandler(object key, Delegate value)
Removes a delegate from the list.
Provides the base implementation for the T:System.ComponentModel.IComponent interface and enables obj...
Definition: Component.cs:9
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: Delegate.cs:15
void AddHandlers(EventHandlerList listToAddFrom)
Adds a list of delegates to the current list.