Another snippet to create an event with its own event argument.
It requires three snippet parameter: the event name (e.g.: DownloadCompleted, ActionStarted, etc.), the parameter type and the parameter name (which is also used to create a property in the event args)
It will create the delegate, the event, the eventarg class and two methods to fire the event.
#region Event $EventName$
/// <summary>
/// Event Arguments for $EventName$
/// </summary>
public class $EventName$EventArgs : EventArgs
{
$ParameterType$ _$EventParameter$;
public $EventName$EventArgs($ParameterType$ $EventParameter$)
{
this._$EventParameter$ = $EventParameter$;
}
public $ParameterType$ $EventParameter$
{
get { return _$EventParameter$; }
}
}
public event System.EventHandler<$EventName$EventArgs> $EventName$;
public delegate void $EventName$Handler(object sender, $EventName$EventArgs e);
/// <summary>
/// Raise the $EventName$ Event
/// </summary>
private void On$EventName$($EventName$EventArgs e)
{
if($EventName$ != null)
{
$EventName$(this, e);
}
}
/// <summary>
/// Raise the $EventName$ Event
/// </summary>
private void On$EventName$($ParameterType$ e)
{
On$EventName$(new $EventName$EventArgs(e));
}
#endregion