/// <summary> /// Executes the provided method while preventing all participating event handlers from reacting to it. /// </summary> /// <param name="source">An object that supports the bypassing of event handlers.</param> /// <param name="action">The method to execute while bypassing all participating event handlers.</param> public static void BypassHandlers(this IHandlerBypassable source, Action action) { Require.NotNull(source, nameof(source)); Require.NotNull(action, nameof(action)); source.HandlersBypassed = true; action(); source.HandlersBypassed = false; }
/// <summary> /// Gets a value indicating if event handlers should be bypassed. /// </summary> /// <param name="source">An object that supports the bypassing of event handlers.</param> /// <returns>True if <c>source</c> is bypassing handlers; otherwise, false.</returns> /// <remarks> /// This value returned by this method should be consulted by all implementations of <see cref="IHandlerBypassable"/> /// prior to the execution of any consequential code in an event handler. /// </remarks> public static bool IsHandlingBypassed(this IHandlerBypassable source) { Require.NotNull(source, nameof(source)); return(source.HandlersBypassed); }