Ejemplo n.º 1
0
        /// <summary>
        /// 为该请求配置一个处理程序。
        /// </summary>
        /// <param name="requestConfigurator">请求配置。</param>
        /// <param name="handler">处理程序。</param>
        /// <exception cref="ArgumentNullException"><paramref name="requestConfigurator"/> 或 <paramref name="handler"/> 为 null。</exception>
        public static void Handle(this RequestConfigurator requestConfigurator, Action handler)
        {
            if (requestConfigurator == null)
            {
                throw new ArgumentNullException("requestConfigurator");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            requestConfigurator.Handle(responseMessage => handler());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 为该请求配置一个处理程序。
        /// </summary>
        /// <typeparam name="TResponse">响应的消息类型。</typeparam>
        /// <param name="requestConfigurator">请求配置。</param>
        /// <param name="handler">处理程序。</param>
        /// <exception cref="ArgumentNullException"><paramref name="requestConfigurator"/> 或 <paramref name="handler"/> 为 null。</exception>
        public static void Handle <TResponse>(this RequestConfigurator requestConfigurator, Action <TResponse> handler)
        {
            if (requestConfigurator == null)
            {
                throw new ArgumentNullException("requestConfigurator");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            requestConfigurator.Handle(responseMessage =>
            {
                var result = responseMessage.Result;
                //如果响应的结果类型不是需要捕获的类型则跳过。
                if (result is TResponse)
                {
                    handler((TResponse)result);
                }
            });
        }