12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System;
- namespace Wayne.Lib
- {
- /// <summary>
- /// Contains extension methods for firing events.
- /// </summary>
- public static class Events
- {
- /// <summary>
- /// Fires the event if it is not null.
- /// </summary>
- /// <typeparam name="TEventArgs"></typeparam>
- /// <param name="eventHandler"></param>
- /// <param name="sender"></param>
- /// <param name="eventArgs"></param>
- public static void Fire<TEventArgs>(this EventHandler<TEventArgs> eventHandler, object sender, TEventArgs eventArgs)
- where TEventArgs : EventArgs
- {
- if (eventHandler != null)
- {
- eventHandler(sender, eventArgs);
- }
- }
- /// <summary>
- /// Fires the event if it is not null.
- /// </summary>
- /// <param name="eventHandler"></param>
- /// <param name="sender"></param>
- /// <param name="eventArgs"></param>
- public static void Fire(this EventHandler eventHandler, object sender, EventArgs eventArgs)
- {
- if (eventHandler != null)
- {
- eventHandler(sender, eventArgs);
- }
- }
- /// <summary>
- /// Fires the action if not null
- /// </summary>
- /// <param name="action"></param>
- public static void Fire(this Action action)
- {
- if (action != null)
- {
- action();
- }
- }
- /// <summary>
- /// Fires the action if not null
- /// </summary>
- /// <param name="action"></param>
- /// <param name="t"></param>
- public static void Fire<T>(this Action<T> action, T t)
- {
- if (action != null)
- {
- action(t);
- }
- }
- /// <summary>
- /// Fires the action if not null
- /// </summary>
- /// <param name="action"></param>
- /// <param name="t1"></param>
- /// <param name="t2"></param>
- public static void Fire<T1, T2>(this Action<T1, T2> action, T1 t1, T2 t2)
- {
- if (action != null)
- {
- action(t1, t2);
- }
- }
- /// <summary>
- /// Fires the action if not null
- /// </summary>
- /// <param name="action"></param>
- /// <param name="t1"></param>
- /// <param name="t2"></param>
- /// <param name="t3"></param>
- public static void Fire<T1, T2, T3>(this Action<T1, T2, T3> action, T1 t1, T2 t2, T3 t3)
- {
- if (action != null)
- {
- action(t1, t2, t3);
- }
- }
- }
- }
|