Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EventHandlerList.cs
Go to the documentation of this file.
2
3public sealed class EventHandlerList : IDisposable
4{
5 private sealed class ListEntry
6 {
7 internal readonly ListEntry _next;
8
9 internal readonly object _key;
10
12
13 public ListEntry(object key, Delegate handler, ListEntry next)
14 {
15 _next = next;
16 _key = key;
17 _handler = handler;
18 }
19 }
20
22
23 private readonly Component _parent;
24
25 public Delegate? this[object key]
26 {
27 get
28 {
29 ListEntry listEntry = null;
31 {
32 listEntry = Find(key);
33 }
34 return listEntry?._handler;
35 }
36 set
37 {
38 ListEntry listEntry = Find(key);
39 if (listEntry != null)
40 {
41 listEntry._handler = value;
42 }
43 else
44 {
45 _head = new ListEntry(key, value, _head);
46 }
47 }
48 }
49
50 internal EventHandlerList(Component parent)
51 {
52 _parent = parent;
53 }
54
56 {
57 }
58
59 public void AddHandler(object key, Delegate? value)
60 {
61 ListEntry listEntry = Find(key);
62 if (listEntry != null)
63 {
64 listEntry._handler = Delegate.Combine(listEntry._handler, value);
65 }
66 else
67 {
68 _head = new ListEntry(key, value, _head);
69 }
70 }
71
72 public void AddHandlers(EventHandlerList listToAddFrom)
73 {
74 if (listToAddFrom == null)
75 {
76 throw new ArgumentNullException("listToAddFrom");
77 }
78 for (ListEntry listEntry = listToAddFrom._head; listEntry != null; listEntry = listEntry._next)
79 {
80 AddHandler(listEntry._key, listEntry._handler);
81 }
82 }
83
84 public void Dispose()
85 {
86 _head = null;
87 }
88
89 private ListEntry Find(object key)
90 {
91 ListEntry listEntry = _head;
92 while (listEntry != null && listEntry._key != key)
93 {
94 listEntry = listEntry._next;
95 }
96 return listEntry;
97 }
98
99 public void RemoveHandler(object key, Delegate? value)
100 {
101 ListEntry listEntry = Find(key);
102 if (listEntry != null)
103 {
104 listEntry._handler = Delegate.Remove(listEntry._handler, value);
105 }
106 }
107}
ListEntry(object key, Delegate handler, ListEntry next)
void AddHandlers(EventHandlerList listToAddFrom)
void RemoveHandler(object key, Delegate? value)
void AddHandler(object key, Delegate? value)
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379