- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
public static class EventExtensions
{
public static void Fire(this EventHandler eventHandler, object sender)
{
eventHandler.Fire(sender, EventArgs.Empty);
}
public static void Fire(this EventHandler eventHandler, object sender, EventArgs args)
{
eventHandler.FireDelegate(sender, args);
}
public static void Fire<TEA>(this EventHandler<TEA> eventHandler, object sender, TEA args)
where TEA : EventArgs
{
eventHandler .FireDelegate(sender, args);
}
public static void FireDelegate(this Delegate eventHandler, params object[] parameters)
{
if (eventHandler != null)
{
Delegate[] delegates = eventHandler.GetInvocationList();
foreach (var del in delegates)
{
try
{
del.Method.Invoke(del.Target, parameters);
}
catch (Exception e)
{
// use logger here
throw;
}
}
}
}
}