protected bool OnExecuting() { if (Executing != null) { bool cancel = false; CancelableEventHandler handler = Executing; if (handler != null) { var args = new CancelableEventArgs(); foreach (CancelableEventHandler tmp in handler.GetInvocationList()) { tmp(this, args); if (!args.Cancel) { continue; } cancel = true; break; } } return(!cancel); } return(true); }
/// <summary> /// Handles the event with specified sender and handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="handler">The handler.</param> /// <returns><c>true</c> if handling was canceled, /// <c>false</c> otherwise.</returns> public bool Handle ( object sender, CancelableEventHandler handler ) { if (handler == null) { return(false); } Delegate[] list = handler.GetInvocationList(); foreach (CancelableEventHandler eventHandler in list.OfType <CancelableEventHandler>()) { eventHandler(sender, this); if (Cancel) { return(true); } } return(false); }