コード例 #1
0
ファイル: DeepInterceptor.cs プロジェクト: mxProject/Misc
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TRequest"></typeparam>
        /// <typeparam name="TResponse"></typeparam>
        /// <param name="streamWriter"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private IClientStreamWriter <TRequest> CreateClientStreamWriter <TRequest, TResponse>(IClientStreamWriter <TRequest> streamWriter, ClientInterceptorContext <TRequest, TResponse> context)
            where TRequest : class
            where TResponse : class
        {
            Task onComplete(IClientStreamWriter <TRequest> writer)
            {
                async Task func()
                {
                    await writer.CompleteAsync().ConfigureAwait(false);
                }

                return(InterceptClientCompleteRequest(func, context));
            }

            Task onWrite(IClientStreamWriter <TRequest> writer, TRequest request)
            {
                async Task func(TRequest req)
                {
                    await writer.WriteAsync(req).ConfigureAwait(false);
                }

                return(InterceptClientWriteRequest(func, request, context));
            }

            return(streamWriter.Wrap(onComplete, onWrite));
        }