using System;
namespace Umbraco.Cms.Core.Events
{
///
/// Extension methods for cancellable event operations
///
public static class EventExtensions
{
// keep these two for backward compatibility reasons but understand that
// they are *not* part of any scope / event dispatcher / anything...
///
/// Raises a cancelable event and returns a value indicating whether the event should be cancelled.
///
/// The type of the event source.
/// The type of the event data.
/// The event handler.
/// The event source.
/// The event data.
/// A value indicating whether the cancelable event should be cancelled
/// A cancelable event is raised by a component when it is about to perform an action that can be canceled.
public static bool IsRaisedEventCancelled(this TypedEventHandler eventHandler, TArgs args, TSender sender)
where TArgs : CancellableEventArgs
{
if (eventHandler == null) return args.Cancel;
eventHandler(sender, args);
return args.Cancel;
}
///
/// Raises an event.
///
/// The type of the event source.
/// The type of the event data.
/// The event handler.
/// The event source.
/// The event data.
public static void RaiseEvent(this TypedEventHandler eventHandler, TArgs args, TSender sender)
where TArgs : EventArgs
{
if (eventHandler == null) return;
eventHandler(sender, args);
}
}
}