From a209ad7b267c00888e3f14185e61b48c4f970a8d Mon Sep 17 00:00:00 2001 From: Ed Ball Date: Tue, 17 Aug 2021 14:54:23 -0700 Subject: [PATCH] Fix analyzer issues. --- Directory.Build.props | 2 +- src/Faithlife.WebRequests/ByteRange.cs | 8 ++++---- src/Faithlife.WebRequests/Json/AutoWebServiceRequest.cs | 2 ++ .../Json/JsonWebServiceClientBase.cs | 6 +++--- src/Faithlife.WebRequests/Json/JsonWebServiceRequest.cs | 2 +- src/Faithlife.WebRequests/WebHeaderCollectionUtility.cs | 6 +++--- src/Faithlife.WebRequests/WebServiceException.cs | 4 ++-- src/Faithlife.WebRequests/WebServiceRequestBase.cs | 4 +++- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 861ef0d..e15dc06 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ 9.0 enable true - $(NoWarn);1591;1998;NU5105;CA1014 + $(NoWarn);1591;1998;NU5105;CA1014;CA1508 embedded Faithlife FaithlifeWebRequests diff --git a/src/Faithlife.WebRequests/ByteRange.cs b/src/Faithlife.WebRequests/ByteRange.cs index 90e321e..b5eb9b9 100644 --- a/src/Faithlife.WebRequests/ByteRange.cs +++ b/src/Faithlife.WebRequests/ByteRange.cs @@ -14,7 +14,7 @@ public class ByteRange public ByteRange(long from) { if (from < 0) - throw new ArgumentOutOfRangeException("from", from, "The parameter must be a non-negative number."); + throw new ArgumentOutOfRangeException(nameof(from), from, "The parameter must be a non-negative number."); From = from; m_to = null; @@ -28,11 +28,11 @@ public ByteRange(long from) public ByteRange(long from, long to) { if (from < 0) - throw new ArgumentOutOfRangeException("from", from, "The parameter must be a non-negative number."); + throw new ArgumentOutOfRangeException(nameof(from), from, "The parameter must be a non-negative number."); if (to < 0) - throw new ArgumentOutOfRangeException("to", to, "The parameter must be a non-negative number."); + throw new ArgumentOutOfRangeException(nameof(to), to, "The parameter must be a non-negative number."); if (from > to) - throw new ArgumentOutOfRangeException("from", "from cannot be greater than to."); + throw new ArgumentOutOfRangeException(nameof(from), "from cannot be greater than to."); From = from; m_to = to; diff --git a/src/Faithlife.WebRequests/Json/AutoWebServiceRequest.cs b/src/Faithlife.WebRequests/Json/AutoWebServiceRequest.cs index 5a94664..80e12d5 100644 --- a/src/Faithlife.WebRequests/Json/AutoWebServiceRequest.cs +++ b/src/Faithlife.WebRequests/Json/AutoWebServiceRequest.cs @@ -98,7 +98,9 @@ protected override async Task HandleResponseCoreAsync(WebServiceResponseHa { // remove hyphens before looking for property setter by name string headerName = header.Key; +#pragma warning disable CA1307 // Specify StringComparison for clarity string propertyName = headerName.Replace("-", ""); +#pragma warning restore CA1307 // Specify StringComparison for clarity var headerProperty = GetProperty(responseType, propertyName); if (headerProperty?.CanWrite ?? false) { diff --git a/src/Faithlife.WebRequests/Json/JsonWebServiceClientBase.cs b/src/Faithlife.WebRequests/Json/JsonWebServiceClientBase.cs index 48d4687..543fc97 100644 --- a/src/Faithlife.WebRequests/Json/JsonWebServiceClientBase.cs +++ b/src/Faithlife.WebRequests/Json/JsonWebServiceClientBase.cs @@ -17,11 +17,11 @@ public abstract class JsonWebServiceClientBase protected JsonWebServiceClientBase(Uri baseUri, JsonWebServiceClientSettings clientSettings) { if (baseUri is null) - throw new ArgumentNullException("baseUri"); + throw new ArgumentNullException(nameof(baseUri)); if (clientSettings is null) - throw new ArgumentNullException("clientSettings"); + throw new ArgumentNullException(nameof(clientSettings)); if (clientSettings.RequestSettings is object && clientSettings.RequestSettingsCreator is object) - throw new ArgumentException("Only one of RequestSettings and RequestSettingsCreator may be set.", "clientSettings"); + throw new ArgumentException("Only one of RequestSettings and RequestSettingsCreator may be set.", nameof(clientSettings)); m_baseUri = baseUri; m_clientSettings = clientSettings; diff --git a/src/Faithlife.WebRequests/Json/JsonWebServiceRequest.cs b/src/Faithlife.WebRequests/Json/JsonWebServiceRequest.cs index caf3cd7..a3920f2 100644 --- a/src/Faithlife.WebRequests/Json/JsonWebServiceRequest.cs +++ b/src/Faithlife.WebRequests/Json/JsonWebServiceRequest.cs @@ -118,7 +118,7 @@ protected override async Task CreateResponseAsync(WebService try { // parse JSON to desired value - TResponseValue value = JsonUtility.FromJson(json, JsonSettings); + TResponseValue value = JsonUtility.FromJson(json, JsonSettings)!; return new JsonWebServiceResponse(this, statusCode, headers, JsonWebServiceContent.FromValue(value)); } catch (JsonReaderException x) diff --git a/src/Faithlife.WebRequests/WebHeaderCollectionUtility.cs b/src/Faithlife.WebRequests/WebHeaderCollectionUtility.cs index e5905ea..f0fab0e 100644 --- a/src/Faithlife.WebRequests/WebHeaderCollectionUtility.cs +++ b/src/Faithlife.WebRequests/WebHeaderCollectionUtility.cs @@ -23,9 +23,9 @@ public static void Add(this WebHeaderCollection headers, WebHeaderCollection add public static void Add(this WebHeaderCollection headers, string name, string value) { if (string.IsNullOrEmpty(name)) - throw new ArgumentException("Invalid name", "name"); + throw new ArgumentException("Invalid name", nameof(name)); if (value?.Length > 65535) - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); string currentValue = headers[name]; headers[name] = currentValue is null ? value : currentValue + ", " + value; @@ -37,7 +37,7 @@ public static void Add(this WebHeaderCollection headers, string name, string val public static void Add(this WebHeaderCollection headers, HttpRequestHeader header, string value) { if (value?.Length > 65535) - throw new ArgumentOutOfRangeException("value"); + throw new ArgumentOutOfRangeException(nameof(value)); string currentValue = headers[header]; headers[header] = currentValue is null ? value : currentValue + ", " + value; diff --git a/src/Faithlife.WebRequests/WebServiceException.cs b/src/Faithlife.WebRequests/WebServiceException.cs index d4c68cd..5102b9c 100644 --- a/src/Faithlife.WebRequests/WebServiceException.cs +++ b/src/Faithlife.WebRequests/WebServiceException.cs @@ -131,12 +131,12 @@ public override string Message message.Append(" (status ").Append(ResponseStatusCode.Value); if (ResponseContentType is object) - message.Append(", content type '").Append(ResponseContentType).Append("'"); + message.Append(", content type '").Append(ResponseContentType).Append('\''); if (ResponseContentLength is object) message.Append(", content length ").AppendInvariant(ResponseContentLength.Value); - message.Append(")"); + message.Append(')'); } return message.ToString(); diff --git a/src/Faithlife.WebRequests/WebServiceRequestBase.cs b/src/Faithlife.WebRequests/WebServiceRequestBase.cs index 03d07a6..4470c80 100644 --- a/src/Faithlife.WebRequests/WebServiceRequestBase.cs +++ b/src/Faithlife.WebRequests/WebServiceRequestBase.cs @@ -206,7 +206,9 @@ private HttpClient CreateHttpClient(WebServiceRequestSettings settings) if (settings.GetHttpClient is object) return settings.GetHttpClient(); +#pragma warning disable CA5399 // HttpClient is created without enabling CheckCertificateRevocationList var client = new HttpClient(CreateHttpClientHandler(settings)); +#pragma warning restore CA5399 // HttpClient is created without enabling CheckCertificateRevocationList var timeout = Timeout ?? settings.DefaultTimeout; client.Timeout = timeout ?? System.Threading.Timeout.InfiniteTimeSpan; return client; @@ -326,7 +328,7 @@ private void SetCookie(HttpResponseHeaders headers, Uri requestUri) if (headers.TryGetValues("Set-Cookie", out var values)) { string cookieHeader = values.Join("; "); - if (cookieHeader != "") + if (!string.IsNullOrEmpty(cookieHeader)) Settings.CookieManager.SetCookies(requestUri, cookieHeader); } }