plugins: change return codes of geany_load_module() and GeanyPluginFuncs::init
[geany-mirror.git] / tests / ctags / events.cs
blobc63138d7fbe00b9b89015cb182f9cb37a3ef9df7
1 // events1.cs
2 using System;
3 namespace MyCollections
5 using System.Collections;
7 // A delegate type for hooking up change notifications.
8 public delegate void ChangedEventHandler(object sender, EventArgs e);
10 // A class that works just like ArrayList, but sends event
11 // notifications whenever the list changes.
12 public class ListWithChangedEvent: ArrayList
14 // An event that clients can use to be notified whenever the
15 // elements of the list change.
16 public event ChangedEventHandler Changed;
18 // Invoke the Changed event; called whenever list changes
19 protected virtual void OnChanged(EventArgs e)
21 if (Changed != null)
22 Changed(this, e);
25 // Override some of the methods that can change the list;
26 // invoke event after each
27 public override int Add(object value)
29 int i = base.Add(value);
30 OnChanged(EventArgs.Empty);
31 return i;
34 public override void Clear()
36 base.Clear();
37 OnChanged(EventArgs.Empty);
40 public override object this[int index]
42 set
44 base[index] = value;
45 OnChanged(EventArgs.Empty);
51 namespace TestEvents
53 using MyCollections;
55 class EventListener
57 private ListWithChangedEvent List;
59 public EventListener(ListWithChangedEvent list)
61 List = list;
62 // Add "ListChanged" to the Changed event on "List".
63 List.Changed += new ChangedEventHandler(ListChanged);
66 // This will be called whenever the list changes.
67 private void ListChanged(object sender, EventArgs e)
69 Console.WriteLine("This is called when the event fires.");
72 public void Detach()
74 // Detach the event and delete the list
75 List.Changed -= new ChangedEventHandler(ListChanged);
76 List = null;
80 class Test
82 // Test the ListWithChangedEvent class.
83 public static void Main()
85 // Create a new list.
86 ListWithChangedEvent list = new ListWithChangedEvent();
88 // Create a class that listens to the list's change event.
89 EventListener listener = new EventListener(list);
91 // Add and remove items from the list.
92 list.Add("item 1");
93 list.Clear();
94 listener.Detach();
99 // events2.cs
100 using System;
101 namespace MyCollections
103 using System.Collections;
105 // A class that works just like ArrayList, but sends event
106 // notifications whenever the list changes:
107 public class ListWithChangedEvent: ArrayList
109 // An event that clients can use to be notified whenever the
110 // elements of the list change:
111 public event EventHandler Changed;
113 // Invoke the Changed event; called whenever list changes:
114 protected virtual void OnChanged(EventArgs e)
116 if (Changed != null)
117 Changed(this,e);
120 // Override some of the methods that can change the list;
121 // invoke event after each:
122 public override int Add(object value)
124 int i = base.Add(value);
125 OnChanged(EventArgs.Empty);
126 return i;
129 public override void Clear()
131 base.Clear();
132 OnChanged(EventArgs.Empty);
135 public override object this[int index]
137 set
139 base[index] = value;
140 OnChanged(EventArgs.Empty);
146 namespace TestEvents
148 using MyCollections;
150 class EventListener
152 private ListWithChangedEvent List;
154 public EventListener(ListWithChangedEvent list)
156 List = list;
157 // Add "ListChanged" to the Changed event on "List":
158 List.Changed += new EventHandler(ListChanged);
161 // This will be called whenever the list changes:
162 private void ListChanged(object sender, EventArgs e)
164 Console.WriteLine("This is called when the event fires.");
167 public void Detach()
169 // Detach the event and delete the list:
170 List.Changed -= new EventHandler(ListChanged);
171 List = null;
175 class Test
177 // Test the ListWithChangedEvent class:
178 public static void Main()
180 // Create a new list:
181 ListWithChangedEvent list = new ListWithChangedEvent();
183 // Create a class that listens to the list's change event:
184 EventListener listener = new EventListener(list);
186 // Add and remove items from the list:
187 list.Add("item 1");
188 list.Clear();
189 listener.Detach();