From 1c56e32a5e2412a3bddc57fdb2c8bb87e8d87507 Mon Sep 17 00:00:00 2001 From: Hans Bakker Date: Sat, 17 Aug 2024 04:31:22 +0200 Subject: [PATCH] Add MemberNotNullWhen annotation for Content / HasContent pair (#1779) * 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 --- Directory.Build.props | 2 +- Refit.GeneratorTests/Refit.GeneratorTests.csproj | 2 +- Refit.GeneratorTests/ReturnTypeTests.cs | 3 +-- .../API/ApiApprovalTests.Refit.DotNet6_0.verified.txt | 2 ++ .../API/ApiApprovalTests.Refit.DotNet8_0.verified.txt | 2 ++ Refit/ApiException.cs | 6 +++++- version.json | 2 +- 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 1694c5b65..a74ab1597 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -36,7 +36,7 @@ - + diff --git a/Refit.GeneratorTests/Refit.GeneratorTests.csproj b/Refit.GeneratorTests/Refit.GeneratorTests.csproj index 442eb0149..74506732f 100644 --- a/Refit.GeneratorTests/Refit.GeneratorTests.csproj +++ b/Refit.GeneratorTests/Refit.GeneratorTests.csproj @@ -20,7 +20,7 @@ - + diff --git a/Refit.GeneratorTests/ReturnTypeTests.cs b/Refit.GeneratorTests/ReturnTypeTests.cs index 1e9605b6e..099a888dd 100644 --- a/Refit.GeneratorTests/ReturnTypeTests.cs +++ b/Refit.GeneratorTests/ReturnTypeTests.cs @@ -1,6 +1,5 @@ -namespace Refit.GeneratorTests; +namespace Refit.GeneratorTests; -[UsesVerify] public class ReturnTypeTests { [Fact] diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index 15d17e534..f5e519fed 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -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; } diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index 8c9b3cce6..cbe45beb8 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -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; } diff --git a/Refit/ApiException.cs b/Refit/ApiException.cs index 5db3d5c5d..7959e7df3 100644 --- a/Refit/ApiException.cs +++ b/Refit/ApiException.cs @@ -1,4 +1,5 @@ -using System.Net; +using System.Diagnostics.CodeAnalysis; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -53,6 +54,9 @@ public class ApiException : Exception /// /// Does the response have content? /// + #if NET6_0_OR_GREATER + [MemberNotNullWhen(true, nameof(Content))] + #endif public bool HasContent => !string.IsNullOrWhiteSpace(Content); /// diff --git a/version.json b/version.json index 20873affd..cc296dfba 100644 --- a/version.json +++ b/version.json @@ -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