using System;
namespace Extension
{
///
/// Provides extension methods to facilitate raising events
///
public static class EventExtension
{
///
/// Raise an event with a given EventArgs
///
/// EventHandler to raised
/// Sender of the event
/// Argument of the event
public static void Raise(this EventHandler handler, object sender, EventArgs e)
{
if (handler != null)
{
handler(sender, e);
}
}
///
/// Raise an event with empty EventArgs
///
/// EventHandler to raised
/// Sender of the event
public static void Raise(this EventHandler handler, object sender)
{
if (handler != null)
{
handler(sender, EventArgs.Empty);
}
}
///
/// Raise an event with a generic EventHandler
///
/// Type of EventArgs to use
/// EventHandler to raised
/// Sender of the event
/// Argument of the event
public static void Raise(this EventHandler handler, object sender, T e)
where T : EventArgs
{
if (handler != null)
{
handler(sender, e);
}
}
}
}