diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 9d59e2572..c6f70a00b 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -16,14 +16,10 @@
true
$(NoWarn);1591
-
- true
- false
-
-
+
diff --git a/src/RestSharp/Request/RequestContent.cs b/src/RestSharp/Request/RequestContent.cs
index 2842c4b30..6404cf4eb 100644
--- a/src/RestSharp/Request/RequestContent.cs
+++ b/src/RestSharp/Request/RequestContent.cs
@@ -162,7 +162,7 @@ void AddPostParameters(ParametersCollection? postParameters) {
var formContent = new FormUrlEncodedContent(
_request.Parameters
.Where(x => x.Type == ParameterType.GetOrPost)
- .Select(x => new KeyValuePair(x.Name!, x.Value!.ToString()!))
+ .Select(x => new KeyValuePair(x.Name!, x.Value!.ToString()!))!
);
Content = formContent;
}
diff --git a/src/RestSharp/RestClient.cs b/src/RestSharp/RestClient.cs
index a2d0b44c2..b80a616ea 100644
--- a/src/RestSharp/RestClient.cs
+++ b/src/RestSharp/RestClient.cs
@@ -45,7 +45,7 @@ public partial class RestClient : IDisposable {
HttpClient HttpClient { get; }
- internal RestClientOptions Options { get; }
+ public RestClientOptions Options { get; }
public RestClient(RestClientOptions options, Action? configureDefaultHeaders = null) {
UseDefaultSerializers();
@@ -83,19 +83,32 @@ public RestClient(Uri baseUrl) : this(new RestClientOptions { BaseUrl = baseUrl
///
public RestClient(string baseUrl) : this(new Uri(Ensure.NotEmptyString(baseUrl, nameof(baseUrl)))) { }
- public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool disposeHttpClient = false) {
- if (options?.CookieContainer != null) {
+ public RestClient(HttpClient httpClient, bool disposeHttpClient = false) {
+ UseDefaultSerializers();
+
+ HttpClient = httpClient;
+ CookieContainer = new CookieContainer();
+ Options = new RestClientOptions();
+ _disposeHttpClient = disposeHttpClient;
+
+ if (httpClient.BaseAddress != null) {
+ Options.BaseUrl = httpClient.BaseAddress;
+ }
+ }
+
+ public RestClient(HttpClient httpClient, RestClientOptions options, bool disposeHttpClient = false) {
+ if (options.CookieContainer != null) {
throw new ArgumentException("Custom cookie container cannot be added to the HttpClient instance", nameof(options.CookieContainer));
}
UseDefaultSerializers();
HttpClient = httpClient;
- Options = options ?? new RestClientOptions();
CookieContainer = new CookieContainer();
+ Options = options;
_disposeHttpClient = disposeHttpClient;
- if (httpClient.BaseAddress != null && Options.BaseUrl == null) {
+ if (httpClient.BaseAddress != null && options.BaseUrl == null) {
Options.BaseUrl = httpClient.BaseAddress;
}
@@ -108,7 +121,7 @@ public RestClient(HttpClient httpClient, RestClientOptions? options = null, bool
///
/// Message handler instance to use for HttpClient
/// Dispose the handler when disposing RestClient, true by default
- public RestClient(HttpMessageHandler handler, bool disposeHandler = true) : this(new HttpClient(handler, disposeHandler), null, true) { }
+ public RestClient(HttpMessageHandler handler, bool disposeHandler = true) : this(new HttpClient(handler, disposeHandler), true) { }
void ConfigureHttpClient(HttpClient httpClient) {
if (Options.Timeout > 0) httpClient.Timeout = TimeSpan.FromMilliseconds(Options.Timeout);
@@ -159,7 +172,7 @@ public RestClient AddDefaultParameter(Parameter parameter) {
);
if (!Options.AllowMultipleDefaultParametersWithSameName &&
- !MultiParameterTypes.Contains(parameter.Type) &&
+ !MultiParameterTypes.Contains(parameter.Type) &&
DefaultParameters.Any(x => x.Name == parameter.Name)) {
throw new ArgumentException("A default parameters with the same name has already been added", nameof(parameter));
}
@@ -218,4 +231,4 @@ public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
-}
+}
\ No newline at end of file