예제 #1
0
        /// <summary>
        /// Adds a handler that is called if the item being matched is of type <typeparamref name="T"/>.
        /// The handler should return <c>true</c> if the item sent in matched and was handled.
        /// <remarks>Note that if a previous added handler handled the item, this <paramref name="handler"/> will not be invoked.</remarks>
        /// </summary>
        /// <typeparam name="T">The type that it must match in order for <paramref name="handler"/> to be called.</typeparam>
        /// <param name="handler">The handler that is invoked. It should return <c>true</c> if the item sent in matched and was handled.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// This exception is thrown if the current state is unknown.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// This exception is thrown if a handler that catches all messages has been added or a partial action has already been built.
        /// </exception>
        public void Match <T>(Func <T, bool> handler) where T : TItem
        {
            EnsureCanAdd();
            var handlesType = typeof(T);

            AddHandler(handlesType, PredicateAndHandler.CreateFunc(handler));
        }
예제 #2
0
 /// <summary>
 /// Adds a handler that is called if the item being matched is of type <paramref name="handlesType"/>.
 /// The handler should return <c>true</c> if the item sent in matched and was handled.
 /// <remarks>Note that if a previous added handler handled the item, this <paramref name="handler"/> will not be invoked.</remarks>
 /// </summary>
 /// <param name="handlesType">The type that it must match in order for <paramref name="handler"/> to be called.</param>
 /// <param name="handler">The handler that is invoked. It should return <c>true</c> if the item sent in matched and was handled.</param>
 /// <exception cref="ArgumentException">
 /// This exception is thrown if the given <paramref name="handler"/> cannot handle the given <paramref name="handlesType"/>.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// This exception is thrown if the current state is unknown.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// This exception is thrown if a handler that catches all messages has been added or a partial action has already been built.
 /// </exception>
 public void Match(Type handlesType, Func <TItem, bool> handler)
 {
     EnsureCanAdd();
     EnsureCanHandleType(handlesType);
     AddHandler(handlesType, PredicateAndHandler.CreateFunc(handler, true));
 }