-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Conversation
…ApiResponse<T> interface
This is similar to Breaking Change because
For some reason I was sure that it was possible to use virtual. Ok, then we should consider using new, but this can also cause some problems |
@ChrisPulman oopsie, I'm sorry. I have forgotten to add |
Update APIResponse as MemberNotNullWhen needs to be in same interface as members
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1672 +/- ##
==========================================
- Coverage 87.73% 87.68% -0.05%
==========================================
Files 33 33
Lines 2348 2323 -25
Branches 294 289 -5
==========================================
- Hits 2060 2037 -23
Misses 208 208
+ Partials 80 78 -2 ☔ View full report in Codecov by Sentry. |
@ChrisPulman did you have time to check how analyzer react on |
I have a PR that needs to go in to revert the targets back to Net6.0, Net8.0, the current code still has the NET6.0_Or_Greater flags |
I have now merged my PR, I will add the tests you have shared pictorially, and we can go from there. Note for next time, adding tests to show how your change will work helps us to understand your use case, it also means that once we accept that we can ensure nothing else breaks this functionality without us knowing. |
I ran the tests and the attributes don't seem to do anything, something is wrong here. I understand the Attributes are supposed to return a non-null value when the condition is met.
What are your thoughts on this? |
@ChrisPulman let me look closer later today |
@sguryev thank you, the attributes really seem to be doing nothing, I have tested them in a plain library ensured that it was Nullable but nothing happens. In theory they are great but only if they do the task required |
@ChrisPulman Unfortunately it's not something you can easily test with unit testing. It's about null-state static analysis. You can find explanation here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/attributes/nullable-analysis#helper-methods-membernotnull-and-membernotnullwhen I have also prepared the sample you can try. Please notice the
Program:
You should see something like this: There is a bunch of warnings which can be threated as errors in order to prevent assign nullable ref types to non-null ref types to avoid null-ref exceptions in runtime. According to the current code in Refit I think than Please let me know if you have any questions
|
Really sorry, would it be possible for you to create a new PR with the updated version. I will try to come up with a test that we can prove this works and ensure that future changes maintain the functionality |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Potential fix for #1671
An alternative way:
new bool IsSuccessStatusCode { get; }
property in theIApiResponse<T>
interface with all 3 attributes above