You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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))]
I've looked through ApiResponse and ApiException and have added one more property to the list. I haven't looked through the rest of the API as I'm not too familiar (yet!) with the project and I unfortunately don't have the time right now to look through everything.
If you can point me to the exact properties that could also use this change I'd be happy to make another commit.
Activity
clairernovotny commentedon Feb 3, 2022
Can you please share a sample interface definition that matches what you're doing? It's not clear what the type of
responseis here.dannyBies commentedon Feb 3, 2022
This happens for every call that uses
ApiResponserefit/Refit/ApiResponse.cs
Line 45 in 569108a
An example could be:
clairernovotny commentedon Feb 3, 2022
Can you please submit a PR to add the correct attributes?
dannyBies commentedon Feb 3, 2022
I've submitted a PR, thanks!
clairernovotny commentedon Feb 3, 2022
Are there other places in the public API that we need to decorate with the nullable attributes to be more accurate?
dannyBies commentedon Feb 3, 2022
I've looked through
ApiResponseandApiExceptionand have added one more property to the list. I haven't looked through the rest of the API as I'm not too familiar (yet!) with the project and I unfortunately don't have the time right now to look through everything.If you can point me to the exact properties that could also use this change I'd be happy to make another commit.
clairernovotny commentedon Feb 3, 2022
Thanks!
github-actions commentedon Apr 13, 2023
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.