Add workaround and missing [MemberNotNullWhen]
attributes
#1879
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
This is the second attempt to add
[MemberNotNullWhen]
attribute forContent
property ofIApiResponse<T>
.Issue #1671
What is the current behavior?
Analyzer doesn't know that
Content
is not null ifIsSuccessStatusCode
istrue
.What is the new behavior?
Analyzer sees new attributes and doesn't show warning\error about possible null ref.
What might this PR break?
I hope nothing.
new
properties to the derived interface otherwise Rider shows the waring and analyzer ignores attribute for property, declared in the base interface.But we are not going to add explicit implementation and
ApiResponse<T>
class issealed
so nobody will be able to make a derived class with explicit base implementation.IApiResponseBase
)new
properties in theIApiResponse<T>
interface (with summary and[SuppressMessage]
) just for making[MemberNotNullWhen]
work. But they are wrapped with#if NET6_0_OR_GREATER
directive so will be invisible for older frameworks.new
behavior forinterface
is safer than forclass
so I can't imagine any other problems we may have.Please check if the PR fulfills these requirements
not applicable - [ ] Tests for the changes have been added (for bug fixes / features)
not applicable - [ ] Docs have been added / updated (for bug fixes / features)
Other information:
I hope we finally can get rid of this annoying additional check we have everywhere now