public static IAdvancedTypedBuilder WithContextItem(this IAdvancedTypedBuilder builder, string key, object value)
        {
            builder.WithConfiguration((ITypedBuilderSettings s) => s.Items[key] = value);

            return(builder);
        }
        public static IAdvancedTypedBuilder WithSuppressTypeMismatchExceptions(this IAdvancedTypedBuilder builder, bool suppress = true)
        {
            builder.WithConfiguration(s => s.SuppressTypeMismatchExceptions = suppress);

            return(builder);
        }
 public static IAdvancedTypedBuilder WithHeadersConfiguration(this IAdvancedTypedBuilder builder, Action <HttpRequestHeaders> configuration)
 {
     return(builder.Advanced.WithConfiguration(b => b.WithHeadersConfiguration(configuration)));
 }
        public static IAdvancedTypedBuilder WithExceptionFactory(this IAdvancedTypedBuilder builder, Func <ExceptionCreationContext, Exception> factory)
        {
            builder.WithConfiguration(s => s.ExceptionFactory = factory);

            return(builder);
        }
        public static IAdvancedTypedBuilder WithHttpHandler(this IAdvancedTypedBuilder builder, IHttpHandler httpHandler)
        {
            builder.WithConfiguration(s => s.HandlerRegister.WithHandler(httpHandler));

            return(builder);
        }
        public static IAdvancedTypedBuilder WithOptionalHttpHandlerConfiguration <THandler>(this IAdvancedTypedBuilder builder, Action <THandler> configure)
            where THandler : class, ITypedHandler
        {
            builder.WithConfiguration(s => s.HandlerRegister.WithConfiguration(configure, false));

            return(builder);
        }
        public static IAdvancedTypedBuilder WithErrorFactory <TError>(this IAdvancedTypedBuilder builder, Func <ITypedBuilderContext, HttpRequestMessage, HttpResponseMessage, Exception, Task <TError> > errorFactory)
        {
            builder.WithConfiguration(s => s.WithResultType(typeof(TError)).ErrorFactory = async(ctx, request, response, ex) => await errorFactory(ctx, request, response, ex));

            return(builder);
        }
        public static IAdvancedTypedBuilder WithMediaTypeFormatterConfiguration <TFormatter>(this IAdvancedTypedBuilder builder, Action <TFormatter> configure) where TFormatter : MediaTypeFormatter
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            builder.WithConfiguration(s =>
            {
                var formatter = s.Formatter.MediaTypeFormatters.OfType <TFormatter>().FirstOrDefault();

                if (formatter != null)
                {
                    configure(formatter);
                }
            });

            return(builder);
        }
        public static IAdvancedTypedBuilder WithResultFactory(this IAdvancedTypedBuilder builder, Func <ITypedBuilderContext, HttpRequestMessage, HttpResponseMessage, Task <object> > resultFactory)
        {
            builder.WithConfiguration(s => s.ResultFactory = resultFactory);

            return(builder);
        }
        public static IAdvancedTypedBuilder WithContentEncoding(this IAdvancedTypedBuilder builder, Encoding encoding)

        {
            return(builder.Advanced.WithConfiguration(b => b.WithContentEncoding(encoding)));
        }
        public static IAdvancedTypedBuilder WithResultFactory <TResult>(this IAdvancedTypedBuilder builder, Func <ITypedBuilderContext, HttpRequestMessage, HttpResponseMessage, Task <TResult> > resultFactory)
        {
            builder.WithConfiguration(s => s.WithResultType(typeof(TResult)).ResultFactory = async(ctx, request, response) => await resultFactory(ctx, request, response));

            return(builder);
        }
        public static IAdvancedTypedBuilder WithHttpContentFactory(this IAdvancedTypedBuilder builder, Func <ITypedBuilderContext, object, Task <HttpContent> > contentFactory)
        {
            builder.WithConfiguration(s => s.HttpContentFactory = contentFactory);

            return(builder);
        }
        public static IAdvancedTypedBuilder WithHttpContentFactory <TContent>(this IAdvancedTypedBuilder builder, Func <ITypedBuilderContext, object, Task <HttpContent> > contentFactory)
        {
            builder.WithConfiguration(s => s.WithContentType(typeof(TContent)).HttpContentFactory = async(ctx, content) => await contentFactory(ctx, content));

            return(builder);
        }
        public static IAdvancedTypedBuilder WithHeader(this IAdvancedTypedBuilder builder, string name, string value)

        {
            return(builder.Advanced.WithConfiguration(b => b.WithHeader(name, value)));
        }
        public static IAdvancedTypedBuilder WithErrorFactory(this IAdvancedTypedBuilder builder, Func <ITypedBuilderContext, HttpRequestMessage, HttpResponseMessage, Exception, Task <object> > errorFactory)
        {
            builder.WithConfiguration(s => s.ErrorFactory = errorFactory);

            return(builder);
        }
        public static IAdvancedTypedBuilder OnSending(this IAdvancedTypedBuilder builder, Action <TypedSendingContext <object, object> > handler)
        {
            builder.WithConfiguration(s => s.HandlerRegister.WithSendingHandler(handler));

            return(builder);
        }
        public static IAdvancedTypedBuilder WithMediaTypeFormatter(this IAdvancedTypedBuilder builder, MediaTypeFormatter formatter)
        {
            builder.WithConfiguration(s => s.Formatter.MediaTypeFormatters.Add(formatter));

            return(builder);
        }