diff --git a/src/Flurl.CodeGen/CodeWriter.cs b/src/Flurl.CodeGen/CodeWriter.cs
index 7c0efa58..ee1650f5 100644
--- a/src/Flurl.CodeGen/CodeWriter.cs
+++ b/src/Flurl.CodeGen/CodeWriter.cs
@@ -18,7 +18,7 @@ public CodeWriter(string filePath)
}
///
- /// use @0, @1, @2, etc for tokens. ({0} would be a pain because you'd alway need to escape "{" and "}")
+ /// use @0, @1, @2, etc. for tokens. ({0} would be a pain because you'd always need to escape "{" and "}")
///
public CodeWriter WriteLine(string line, params object[] args)
{
@@ -30,7 +30,7 @@ public CodeWriter WriteLine(string line, params object[] args)
line = line.Replace("@" + i, val);
}
- if (line == "}" || line == "{")
+ if (line is "}" or "{")
{
_indent--;
}
diff --git a/src/Flurl.CodeGen/HttpExtensionMethod.cs b/src/Flurl.CodeGen/HttpExtensionMethod.cs
index e3dfd843..d9520b28 100644
--- a/src/Flurl.CodeGen/HttpExtensionMethod.cs
+++ b/src/Flurl.CodeGen/HttpExtensionMethod.cs
@@ -40,7 +40,7 @@ public HttpExtensionMethod(string verb, bool isGeneric, string reqBodyType, stri
" an asynchronous ",
(HttpVerb == null) ? "request." : $"{HttpVerb.ToUpperInvariant()} request.");
- public bool HasRequestBody => (HttpVerb == "Post" || HttpVerb == "Put" || HttpVerb == "Patch" || HttpVerb == null);
+ public bool HasRequestBody => HttpVerb is "Post" or "Put" or "Patch" or null;
public string HttpVerb { get; }
public string RequestBodyType { get; }
diff --git a/src/Flurl.CodeGen/Metadata.cs b/src/Flurl.CodeGen/Metadata.cs
index 0bf9f392..645735c2 100644
--- a/src/Flurl.CodeGen/Metadata.cs
+++ b/src/Flurl.CodeGen/Metadata.cs
@@ -1,7 +1,5 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
-using System.Text;
namespace Flurl.CodeGen
{
diff --git a/src/Flurl.Http.Newtonsoft/ExtensionMethods.cs b/src/Flurl.Http.Newtonsoft/ExtensionMethods.cs
index 5c18248b..830c80f9 100644
--- a/src/Flurl.Http.Newtonsoft/ExtensionMethods.cs
+++ b/src/Flurl.Http.Newtonsoft/ExtensionMethods.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Dynamic;
using System.Threading.Tasks;
using Flurl.Http.Configuration;
diff --git a/src/Flurl.Http/Configuration/FlurlClientBuilder.cs b/src/Flurl.Http/Configuration/FlurlClientBuilder.cs
index 44d1a4d2..d746e2dd 100644
--- a/src/Flurl.Http/Configuration/FlurlClientBuilder.cs
+++ b/src/Flurl.Http/Configuration/FlurlClientBuilder.cs
@@ -1,9 +1,11 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
-using System.Runtime.Versioning;
using Flurl.Util;
+#if NET
+using System.Runtime.Versioning;
+#endif
namespace Flurl.Http.Configuration
{
@@ -42,6 +44,11 @@ public interface IFlurlClientBuilder : ISettingsContainer, IHeadersContainer, IE
/// Builds an instance of IFlurlClient based on configurations specified.
///
IFlurlClient Build();
+
+ ///
+ /// Configure factory
+ ///
+ void WithFactory(Func create);
}
///
@@ -72,6 +79,9 @@ public FlurlClientBuilder(string baseUrl = null) {
_baseUrl = baseUrl;
}
+ ///
+ public void WithFactory(Func create) => _factory = create();
+
///
public IFlurlClientBuilder AddMiddleware(Func create) {
_addMiddleware.Add(create);
@@ -103,7 +113,7 @@ public IFlurlClientBuilder UseSocketsHttpHandler(Action conf
if (_factory is DefaultFlurlClientFactory && _handlerConfigs.Any())
throw new FlurlConfigurationException("ConfigureInnerHandler and UseSocketsHttpHandler cannot be used together. The former configures and instance of HttpClientHandler and would be ignored when switching to SocketsHttpHandler.");
- if (!(_factory is SocketsHandlerFlurlClientFactory))
+ if (_factory is not SocketsHandlerFlurlClientFactory)
_factory = new SocketsHandlerFlurlClientFactory();
_handlerConfigs.Add(h => configure(h as SocketsHttpHandler));
diff --git a/src/Flurl.Http/Configuration/ISerializer.cs b/src/Flurl.Http/Configuration/ISerializer.cs
index 71b2a87b..6bbadd59 100644
--- a/src/Flurl.Http/Configuration/ISerializer.cs
+++ b/src/Flurl.Http/Configuration/ISerializer.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
+using System.IO;
namespace Flurl.Http.Configuration
{
diff --git a/src/Flurl.Http/Configuration/RedirectSettings.cs b/src/Flurl.Http/Configuration/RedirectSettings.cs
index f39d6e8d..6f9f2796 100644
--- a/src/Flurl.Http/Configuration/RedirectSettings.cs
+++ b/src/Flurl.Http/Configuration/RedirectSettings.cs
@@ -1,11 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Flurl.Http.Configuration
+namespace Flurl.Http.Configuration
{
///
/// A set of properties that affect Flurl.Http behavior specific to auto-redirecting.
diff --git a/src/Flurl.Http/Content/CapturedJsonContent.cs b/src/Flurl.Http/Content/CapturedJsonContent.cs
index 7b2ccd6b..2dab193d 100644
--- a/src/Flurl.Http/Content/CapturedJsonContent.cs
+++ b/src/Flurl.Http/Content/CapturedJsonContent.cs
@@ -1,6 +1,4 @@
-using System.Text;
-
-namespace Flurl.Http.Content
+namespace Flurl.Http.Content
{
///
/// Provides HTTP content based on a serialized JSON object, with the JSON string captured to a property
diff --git a/src/Flurl.Http/Content/CapturedStringContent.cs b/src/Flurl.Http/Content/CapturedStringContent.cs
index 7e26f40e..b303375c 100644
--- a/src/Flurl.Http/Content/CapturedStringContent.cs
+++ b/src/Flurl.Http/Content/CapturedStringContent.cs
@@ -1,6 +1,4 @@
using System.Net.Http;
-using System.Net.Http.Headers;
-using System.Text;
namespace Flurl.Http.Content
{
diff --git a/src/Flurl.Http/FlurlClient.cs b/src/Flurl.Http/FlurlClient.cs
index 474d8568..b80514c8 100644
--- a/src/Flurl.Http/FlurlClient.cs
+++ b/src/Flurl.Http/FlurlClient.cs
@@ -253,7 +253,7 @@ private async Task ProcessRedirectAsync(FlurlCall call, HttpComp
// partially lifted from https://github.com/dotnet/runtime/blob/master/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/RedirectHandler.cs
private static FlurlRedirect GetRedirect(FlurlCall call) {
- if (call.Response.StatusCode < 300 || call.Response.StatusCode > 399)
+ if (call.Response.StatusCode is < 300 or > 399)
return null;
if (!call.Response.Headers.TryGetFirst("Location", out var location))
diff --git a/src/Flurl.Http/FlurlEventHandler.cs b/src/Flurl.Http/FlurlEventHandler.cs
index d9137ea8..4be114e6 100644
--- a/src/Flurl.Http/FlurlEventHandler.cs
+++ b/src/Flurl.Http/FlurlEventHandler.cs
@@ -1,5 +1,4 @@
using System;
-using System.Linq;
using System.Threading.Tasks;
namespace Flurl.Http
diff --git a/src/Flurl.Http/FlurlRequest.cs b/src/Flurl.Http/FlurlRequest.cs
index c98e6649..5ee2efac 100644
--- a/src/Flurl.Http/FlurlRequest.cs
+++ b/src/Flurl.Http/FlurlRequest.cs
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
@@ -184,7 +183,7 @@ private void ApplyCookieJar(CookieJar jar) {
this.WithCookies(
from c in CookieJar
- where c.ShouldSendTo(this.Url, out _)
+ where c.ShouldSendTo(Url, out _)
// sort by longest path, then earliest creation time, per #2: https://tools.ietf.org/html/rfc6265#section-5.4
orderby (c.Path ?? c.OriginUrl.Path).Length descending, c.DateReceived
select (c.Name, c.Value));
diff --git a/src/Flurl.Http/GeneratedExtensions.cs b/src/Flurl.Http/GeneratedExtensions.cs
index 75b39ab3..b6ed706b 100644
--- a/src/Flurl.Http/GeneratedExtensions.cs
+++ b/src/Flurl.Http/GeneratedExtensions.cs
@@ -1,7 +1,6 @@
// This file was auto-generated by Flurl.CodeGen. Do not edit directly.
using System;
using System.IO;
-using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
diff --git a/src/Flurl.Http/HttpMessageExtensions.cs b/src/Flurl.Http/HttpMessageExtensions.cs
index 0c7669dc..7b3d5dee 100644
--- a/src/Flurl.Http/HttpMessageExtensions.cs
+++ b/src/Flurl.Http/HttpMessageExtensions.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Net.Http;
+using System.Net.Http;
using System.Net.Http.Headers;
using Flurl.Http.Content;
using Flurl.Util;
diff --git a/src/Flurl.Http/IHeadersContainer.cs b/src/Flurl.Http/IHeadersContainer.cs
index 366f1b3f..9455e8c2 100644
--- a/src/Flurl.Http/IHeadersContainer.cs
+++ b/src/Flurl.Http/IHeadersContainer.cs
@@ -48,7 +48,7 @@ public static T WithHeaders(this T obj, object headers, bool replaceUnderscor
return obj;
// underscore replacement only applies when object properties are parsed to kv pairs
- replaceUnderscoreWithHyphen = replaceUnderscoreWithHyphen && !(headers is string) && !(headers is IEnumerable);
+ replaceUnderscoreWithHyphen = replaceUnderscoreWithHyphen && headers is not string && headers is not IEnumerable;
foreach (var kv in headers.ToKeyValuePairs()) {
var key = replaceUnderscoreWithHyphen ? kv.Key.Replace("_", "-") : kv.Key;
diff --git a/src/Flurl.Http/ISettingsContainer.cs b/src/Flurl.Http/ISettingsContainer.cs
index 698fd87f..a8364ea2 100644
--- a/src/Flurl.Http/ISettingsContainer.cs
+++ b/src/Flurl.Http/ISettingsContainer.cs
@@ -1,6 +1,4 @@
using System;
-using System.Linq;
-using System.Net;
using Flurl.Http.Configuration;
namespace Flurl.Http
diff --git a/src/Flurl.Http/Testing/Util.cs b/src/Flurl.Http/Testing/Util.cs
index 12c2af83..6ff59004 100644
--- a/src/Flurl.Http/Testing/Util.cs
+++ b/src/Flurl.Http/Testing/Util.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
+using System.Collections;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
@@ -39,7 +37,7 @@ internal static bool HasQueryParam(this FlurlCall call, string name, object valu
if (!paramVals.Any())
return false;
- if (!(value is string) && value is IEnumerable en) {
+ if (value is not string && value is IEnumerable en) {
var values = en.Cast