2015-01-26 13:13:06 +01:00
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
2015-06-24 10:05:12 +02:00
|
|
|
namespace uForum.Extensions
|
2015-01-26 13:13:06 +01:00
|
|
|
{
|
|
|
|
|
public static class EventExtensions
|
|
|
|
|
{
|
|
|
|
|
public static void Raise<T>(this EventHandler<T> handler, object sender, T args) where T : EventArgs
|
|
|
|
|
{
|
|
|
|
|
if (handler != null) handler(sender, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//returns true if there is no handler or if the handler doesnt set Cancel to true
|
|
|
|
|
public static bool RaiseAndContinue<T>(this EventHandler<T> handler, object sender, T args) where T : CancelEventArgs
|
|
|
|
|
{
|
|
|
|
|
if (handler == null)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
handler(sender, args);
|
|
|
|
|
return (args.Cancel != true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|