Skip to content

Commit

Permalink
Add MemberNotNullWhen annotation for Content / HasContent pair (#1779)
Browse files Browse the repository at this point in the history
* Add MemberNotNullWhen annotation for Content / HasContent pair

* Add missing using statement

* Update API Tests

Bump Version due to API change

---------

Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>
  • Loading branch information
hansmbakker and ChrisPulman committed Aug 17, 2024
1 parent c7b8301 commit 1c56e32
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</ItemGroup>

<ItemGroup Condition="'$(IsTestProject)' != 'true'">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Refit.GeneratorTests/Refit.GeneratorTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="System.Collections.Immutable" Version="9.0.0-preview.5.24306.7" />
<PackageReference Include="Verify.DiffPlex" Version="3.1.0" />
<PackageReference Include="Verify.SourceGenerators" Version="2.3.0" />
<PackageReference Include="Verify.Xunit" Version="22.11.5" />
<PackageReference Include="Verify.Xunit" Version="26.2.0" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
Expand Down
3 changes: 1 addition & 2 deletions Refit.GeneratorTests/ReturnTypeTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Refit.GeneratorTests;
namespace Refit.GeneratorTests;

[UsesVerify]
public class ReturnTypeTests
{
[Fact]
Expand Down
2 changes: 2 additions & 0 deletions Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Refit
protected ApiException(string exceptionMessage, System.Net.Http.HttpRequestMessage message, System.Net.Http.HttpMethod httpMethod, string? content, System.Net.HttpStatusCode statusCode, string? reasonPhrase, System.Net.Http.Headers.HttpResponseHeaders headers, Refit.RefitSettings refitSettings, System.Exception? innerException = null) { }
public string? Content { get; }
public System.Net.Http.Headers.HttpContentHeaders? ContentHeaders { get; }
[System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")]
[get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")]
public bool HasContent { get; }
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
public System.Net.Http.HttpMethod HttpMethod { get; }
Expand Down
2 changes: 2 additions & 0 deletions Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Refit
protected ApiException(string exceptionMessage, System.Net.Http.HttpRequestMessage message, System.Net.Http.HttpMethod httpMethod, string? content, System.Net.HttpStatusCode statusCode, string? reasonPhrase, System.Net.Http.Headers.HttpResponseHeaders headers, Refit.RefitSettings refitSettings, System.Exception? innerException = null) { }
public string? Content { get; }
public System.Net.Http.Headers.HttpContentHeaders? ContentHeaders { get; }
[System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")]
[get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")]
public bool HasContent { get; }
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
public System.Net.Http.HttpMethod HttpMethod { get; }
Expand Down
6 changes: 5 additions & 1 deletion Refit/ApiException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;

Expand Down Expand Up @@ -53,6 +54,9 @@ public class ApiException : Exception
/// <summary>
/// Does the response have content?
/// </summary>
#if NET6_0_OR_GREATER
[MemberNotNullWhen(true, nameof(Content))]
#endif
public bool HasContent => !string.IsNullOrWhiteSpace(Content);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "7.1.2",
"version": "7.2.0",
"publicReleaseRefSpec": [
"^refs/heads/main$", // we release out of main
"^refs/heads/rel/v\\d+\\.\\d+" // we also release branches starting with vN.N
Expand Down

0 comments on commit 1c56e32

Please sign in to comment.