API Proposal: MemberNotNullWhenNull #7683
Unanswered
chris-smith-zocdoc
asked this question in
Language Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Today
MemberNotNullWhen
allows methods to change the nullity of a member provided the method returns a boolean. This allows for methods likeint.TryParse
where out parameters & booleans are used together but doesn't allow for handling of other response types which may change the nullity.We have some common use cases where operations are either expected to succeed and return a result value or fail and return an error value. With the introduction of a new attribute like
MemberNotNullWhenNull
we can use the nullity check on one property to modify the nullity of anotherAPI proposal
Example usage
This can also be used as a switch expression. Without
MemberNotNullWhenNull
the switch is not exhaustive because the branches aren't known to be mutually exclusiveBeta Was this translation helpful? Give feedback.
All reactions