Is there a common ancestor or interface shared by EventHandler and KeyEventHandler? I've looked at the documentation and maybe I'm just missing it, but they seem completely disjoint.
Assuming there is no such common link between them, what is the best way to store a collection of many EventHandlers and KeyEventHandlers?
Both KeyEventHandler and EventHandler are delegates. This code works:
public void DelegateTest()
{
var delList = new List<Delegate>();
delList.Add(new KeyEventHandler(SomeFunction));
delList.Add(new EventHandler(SomeFunction));
foreach (var element in delList)
element.DynamicInvoke(null, null);
}
public void SomeFunction(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Got called!");
}
Calling DelegateTest()
will write "Got called!" twice on the output.