Deklaration eines Events.
Es sind nur += und -= offentlich zugänglich.
#region EventName: MyEvent
/// <summary>
/// <see cref="MyEvent"/>
/// </summary>
private event EventHandler<MyEventArgs> _MyEvent;
/// <summary>
/// ...
/// </summary>
public event EventHandler<MyEventArgs> MyEvent
{
add { _MyEvent += value; }
remove { _MyEvent -= value; }
}
/// <summary>
/// ...
/// </summary>
/// <param name="e">The event args
/// instance containing the event data.</param>
protected virtual void OnMyEvent(MyEventArgs e)
{
try
{
if(_MyEvent != null)
{
_MyEvent(this, e);
}
}
catch
{
//TODO: exception handling
throw;
}
}
#endregion
1 Kommentare zum Snippet