Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Fix analyzer issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball committed Aug 17, 2021
1 parent 5d04e85 commit a209ad7
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);1591;1998;NU5105;CA1014</NoWarn>
<NoWarn>$(NoWarn);1591;1998;NU5105;CA1014;CA1508</NoWarn>
<DebugType>embedded</DebugType>
<GitHubOrganization>Faithlife</GitHubOrganization>
<RepositoryName>FaithlifeWebRequests</RepositoryName>
Expand Down
8 changes: 4 additions & 4 deletions src/Faithlife.WebRequests/ByteRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/Faithlife.WebRequests/Json/AutoWebServiceRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ protected override async Task<bool> 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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Faithlife.WebRequests/Json/JsonWebServiceClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Faithlife.WebRequests/Json/JsonWebServiceRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected override async Task<WebServiceResponse> CreateResponseAsync(WebService
try
{
// parse JSON to desired value
TResponseValue value = JsonUtility.FromJson<TResponseValue>(json, JsonSettings);
TResponseValue value = JsonUtility.FromJson<TResponseValue>(json, JsonSettings)!;
return new JsonWebServiceResponse<TResponseValue>(this, statusCode, headers, JsonWebServiceContent.FromValue(value));
}
catch (JsonReaderException x)
Expand Down
6 changes: 3 additions & 3 deletions src/Faithlife.WebRequests/WebHeaderCollectionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Faithlife.WebRequests/WebServiceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/Faithlife.WebRequests/WebServiceRequestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit a209ad7

Please sign in to comment.