ExhaustiveMatching
ExhaustiveMatching copied to clipboard
[Suggestion] Allow optional opt-in for requiring null handling case
Hello!
First of all, I absolutely love this library. I really appreciate your work on it :)
I ran into a case today where I had refactored some code that previously had not allowed null
to be a valid value, but now I have switch
cases throwing ExhaustiveMatch.Failed
. I realized it was because I had not been handling the null
case in the switch
.
In the documentation, I see you have the following:
Since C# reference types are always nullable, but may be intended to never be null, exhaustiveness checking does not require a case for null. If a null value is expected it can be handled by a case null:. The analyzer will ignore this case for its analysis.
For nullable enum types, the analyzer requires that there be a case null: to handle the null value.
I understand that this might not be desired as a default behavior, but I would really personally like to be forced to handle null
on reference types.
Is there any way that we can see this as an opt-in thing in the future? Perhap something we can decorate our assembly with as an attribute, or similar.
Thank you! Anthony
I think this is a good idea and should probably be implemented in concert with #27 "Support C# 8 Nullable Reference Types" to make sure that it plays well with that.