Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1671: Add MemberNotNullWhen attribute for Content property in IApiResponse<T> #1672

Merged
merged 4 commits into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions Refit/ApiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// Implementation of <see cref="IApiResponse{T}"/> that provides additional functionalities.
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class ApiResponse<T> : IApiResponse<T>
public sealed class ApiResponse<T> : IApiResponse<T>, IApiResponse
{
readonly HttpResponseMessage response;
bool disposed;
Expand Down Expand Up @@ -60,6 +60,8 @@
/// </summary>
public T? Content { get; }

object? IApiResponse.Content => Content;

Check warning on line 63 in Refit/ApiResponse.cs

View check run for this annotation

Codecov / codecov/patch

Refit/ApiResponse.cs#L63

Added line #L63 was not covered by tests

/// <summary>
/// Refit settings used to send the request.
/// </summary>
Expand Down Expand Up @@ -163,14 +165,29 @@
/// <summary>
/// Deserialized request content as <typeparamref name="T"/>.
/// </summary>
T? Content { get; }
new T? Content { get; }
}

/// <summary>
/// Base interface used to represent an API response.
/// </summary>
public interface IApiResponse : IDisposable
{
/// <summary>
/// Indicates whether the request was successful.
/// </summary>
#if NET6_0_OR_GREATER
[MemberNotNullWhen(true, nameof(ContentHeaders))]
[MemberNotNullWhen(false, nameof(Error))]
[MemberNotNullWhen(true, nameof(Content))]
#endif
bool IsSuccessStatusCode { get; }

/// <summary>
/// Deserialized request content as an object.
/// </summary>
object? Content { get; }

/// <summary>
/// HTTP response headers.
/// </summary>
Expand All @@ -181,15 +198,6 @@
/// </summary>
HttpContentHeaders? ContentHeaders { get; }

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

/// <summary>
/// HTTP response status code.
/// </summary>
Expand Down