Ejemplo n.º 1
0
        public static bool RaiseUntil <T, K>(this ChainedEventHandler <T, K> delegates, object sender, T args, Predicate <K> predicate) where T : IMutableValueEventArgs <K>
        {
            bool handled = false;

            if (delegates != null)
            {
                Delegate[] invocationList = delegates.GetInvocationList();
                for (int i = 0; i < invocationList.Length && !handled; i++)
                {
                    K result = ((ChainedEventHandler <T, K>)invocationList[i])(sender, args);
                    handled = predicate(result);
                }
            }
            return(handled);
        }
Ejemplo n.º 2
0
        public static bool Raise <T>(this ChainedEventHandler <T> delegates, object sender, T arg)
            where T : ChainedEventArgs
        {
            bool handled = false;

            if (delegates != null)
            {
                Delegate[] invocationList = delegates.GetInvocationList();
                for (int i = 0; i < (int)invocationList.Length && !handled; i++)
                {
                    ((ChainedEventHandler <T>)invocationList[i])(sender, arg);
                    handled = arg.Handled;
                }
            }
            return(handled);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fires each event in the invocation list in the order in which
        /// the events were added until an event handler sets the handled
        /// property to true.
        /// Any exception that the event throws must be caught by the caller.
        /// </summary>
        /// <param name="delegates">The multicast delegate (event).</param>
        /// <param name="sender">The event source instance.</param>
        /// <param name="arg">The event argument.</param>
        /// <returns>Returns true if an event sink handled the event,
        /// false otherwise.</returns>
        public static bool Raise <T>(this ChainedEventHandler <T> delegates, object sender, T arg) where T : ChainedEventArgs
        {
            bool handled = false;

            // Assuming the multicast delegate is not null...
            if (delegates != null)
            {
                // Call the methods until one of them handles the event
                // or all the methods in the delegate list are processed.
                Delegate[] invocationList = delegates.GetInvocationList();

                for (int i = 0; i < invocationList.Length && !handled; i++)
                {
                    ((ChainedEventHandler <T>)invocationList[i])(sender, arg);
                    handled = arg.Handled;
                }
            }
            // Return a flag indicating whether an event sink handled
            // the event.
            return(handled);
        }