From b13cbf2b37f6a749bf1d98c76d3b70d6d285319d Mon Sep 17 00:00:00 2001 From: Serj Date: Fri, 18 Oct 2024 06:28:58 +0700 Subject: [PATCH] Add workaround and missing `[MemberNotNullWhen]` attributes (#1879) * Add workaround and missing MemberNotNullWhen attributes * Fix API Tests --------- Co-authored-by: Chris Pulman --- ...ApprovalTests.Refit.DotNet6_0.verified.txt | 9 +++++++ ...ApprovalTests.Refit.DotNet8_0.verified.txt | 9 +++++++ Refit/ApiResponse.cs | 25 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt index 9b3d7dff7..34fd210ce 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt @@ -198,6 +198,15 @@ namespace Refit public interface IApiResponse : Refit.IApiResponse, System.IDisposable { T Content { get; } + new System.Net.Http.Headers.HttpContentHeaders? ContentHeaders { get; } + new Refit.ApiException? Error { get; } + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Error")] + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "ContentHeaders")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Error")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "ContentHeaders")] + new bool IsSuccessStatusCode { get; } } public interface IFormUrlEncodedParameterFormatter { diff --git a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt index 7295422ec..182ebd24d 100644 --- a/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt +++ b/Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt @@ -198,6 +198,15 @@ namespace Refit public interface IApiResponse : Refit.IApiResponse, System.IDisposable { T Content { get; } + new System.Net.Http.Headers.HttpContentHeaders? ContentHeaders { get; } + new Refit.ApiException? Error { get; } + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Error")] + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] + [System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "ContentHeaders")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(false, "Error")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "Content")] + [get: System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, "ContentHeaders")] + new bool IsSuccessStatusCode { get; } } public interface IFormUrlEncodedParameterFormatter { diff --git a/Refit/ApiResponse.cs b/Refit/ApiResponse.cs index 259a58123..2867b8147 100644 --- a/Refit/ApiResponse.cs +++ b/Refit/ApiResponse.cs @@ -152,6 +152,31 @@ void Dispose(bool disposing) /// public interface IApiResponse : IApiResponse { +#if NET6_0_OR_GREATER + /// + /// The object in case of unsuccessful response. + /// + [SuppressMessage( + "Naming", + "CA1716:Identifiers should not match keywords", + Justification = "By Design" + )] + new ApiException? Error { get; } + + /// + /// HTTP response content headers as defined in RFC 2616. + /// + new HttpContentHeaders? ContentHeaders { get; } + + /// + /// Indicates whether the request was successful. + /// + [MemberNotNullWhen(true, nameof(Content))] + [MemberNotNullWhen(true, nameof(ContentHeaders))] + [MemberNotNullWhen(false, nameof(Error))] + new bool IsSuccessStatusCode { get; } +#endif + /// /// Deserialized request content as . ///