56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
|
|
using System;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
|
|||
|
|
namespace JiShe.CollectBus.Common.Extensions
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Extension methods for <see cref="EventHandler"/>.
|
|||
|
|
/// </summary>
|
|||
|
|
public static class EventHandlerExtensions
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Raises given event safely with given arguments.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="eventHandler">The event handler</param>
|
|||
|
|
/// <param name="sender">Source of the event</param>
|
|||
|
|
[Description("ʹ<>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>")]
|
|||
|
|
public static void InvokeSafely(this EventHandler eventHandler, object sender)
|
|||
|
|
{
|
|||
|
|
eventHandler.InvokeSafely(sender, EventArgs.Empty);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Raises given event safely with given arguments.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="eventHandler">The event handler</param>
|
|||
|
|
/// <param name="sender">Source of the event</param>
|
|||
|
|
/// <param name="e">Event argument</param>
|
|||
|
|
public static void InvokeSafely(this EventHandler eventHandler, object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (eventHandler == null)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
eventHandler(sender, e);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Raises given event safely with given arguments.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <typeparam name="TEventArgs">Type of the <see cref="EventArgs"/></typeparam>
|
|||
|
|
/// <param name="eventHandler">The event handler</param>
|
|||
|
|
/// <param name="sender">Source of the event</param>
|
|||
|
|
/// <param name="e">Event argument</param>
|
|||
|
|
public static void InvokeSafely<TEventArgs>(this EventHandler<TEventArgs> eventHandler, object sender, TEventArgs e)
|
|||
|
|
where TEventArgs : EventArgs
|
|||
|
|
{
|
|||
|
|
if (eventHandler == null)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
eventHandler(sender, e);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|