Skip to content

feature: Improve support for nullable #1302

@dannyBies

Description

@dannyBies

Is your feature request related to a problem? Please describe.

In my project I have nullable reference types enabled <Nullable>enable</Nullable>.

I retrieve data like this:

var response = await RestApi.Users.Query.GetUrl("1234");
if (!response.IsSuccessStatusCode)
{
    Logger.LogError(response.Error.Message);
    return;
}
var url = response.Content.Url;

The issue I'm seeing is that I get CS8602 warnings(Dereference of a possible null reference) for response.Content and response.Error due to these being nullable. However I am checking response.IsSuccessStatusCode which I believe make sure that either Content or Error is populated.

Describe the solution you'd like

To not get these warnings.

Describe suggestions on how to achieve the feature

I believe we can add the following attributes to IsSuccessStatusCode to fix this issue.
[MemberNotNullWhen(true, nameof(Content))]
[MemberNotNullWhen(false, nameof(Error))]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions