Files
HawkeyeVision/framework/Inspectron.Settings/Event.cs
2025-07-14 12:03:59 +02:00

43 lines
1.2 KiB
C#

using System;
using System.ComponentModel;
namespace Inspectron.Settings
{
public static class Event
{
public static void Raise(this EventHandler handler, object sender, EventArgs e)
{
if (handler != null) handler(sender, e);
}
public static void Raise<T>(this EventHandler<T> handler, object sender, T e) where T : EventArgs
{
if (handler != null) handler(sender, e);
}
public static bool RaiseCancellable(this CancelEventHandler handler, object sender, CancelEventArgs e)
{
if (handler != null)
foreach (CancelEventHandler h in handler.GetInvocationList())
{
h(sender, e);
if (e.Cancel) break;
}
return e.Cancel;
}
public static bool RaiseCancellable<T>(this EventHandler<T> handler, object sender, T e)
where T : CancelEventArgs
{
if (handler != null)
foreach (EventHandler<T> h in handler.GetInvocationList())
{
h(sender, e);
if (e.Cancel) break;
}
return e.Cancel;
}
}
}