Skip to content

Commit

Permalink
Add workaround and missing [MemberNotNullWhen] attributes (#1879)
Browse files Browse the repository at this point in the history
* Add workaround and missing MemberNotNullWhen attributes

* Fix API Tests

---------

Co-authored-by: Chris Pulman <[email protected]>
  • Loading branch information
sguryev and ChrisPulman authored Oct 17, 2024
1 parent 396c2bf commit b13cbf2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Refit.Tests/API/ApiApprovalTests.Refit.DotNet6_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ namespace Refit
public interface IApiResponse<out T> : 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
{
Expand Down
9 changes: 9 additions & 0 deletions Refit.Tests/API/ApiApprovalTests.Refit.DotNet8_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ namespace Refit
public interface IApiResponse<out T> : 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
{
Expand Down
25 changes: 25 additions & 0 deletions Refit/ApiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ void Dispose(bool disposing)
/// <inheritdoc/>
public interface IApiResponse<out T> : IApiResponse
{
#if NET6_0_OR_GREATER
/// <summary>
/// The <see cref="ApiException"/> object in case of unsuccessful response.
/// </summary>
[SuppressMessage(
"Naming",
"CA1716:Identifiers should not match keywords",
Justification = "By Design"
)]
new ApiException? Error { get; }

/// <summary>
/// HTTP response content headers as defined in RFC 2616.
/// </summary>
new HttpContentHeaders? ContentHeaders { get; }

/// <summary>
/// Indicates whether the request was successful.
/// </summary>
[MemberNotNullWhen(true, nameof(Content))]
[MemberNotNullWhen(true, nameof(ContentHeaders))]
[MemberNotNullWhen(false, nameof(Error))]
new bool IsSuccessStatusCode { get; }
#endif

/// <summary>
/// Deserialized request content as <typeparamref name="T"/>.
/// </summary>
Expand Down

0 comments on commit b13cbf2

Please sign in to comment.