Open
Description
Background and motivation
The FilePatternMatch.Stem
property seems to be nullable purely because the PatternTestResult.Stem
property it gets its value from is nullable. While the PatternTestResult
can indeed be null if the result is not successful, the FilePatternMatch
never is because it is only ever constructed when PatternTestResult
is successful.
I believe we could add a [MemberNotNullWhen()]
attribute to the PatternTestResult.Stem
property to tell the compiler it will not be null if it is successful and then pass it along to the new non-nullable string constructor of FilePatternMatch
.
API Proposal
+ public string Stem { get; }
- public string? Stem { get; }
+ public FilePatternMatch(string path, string stem)
- public FilePatternMatch(string path, string? stem)
API Usage
var filePatternMatch = new FilePatternMatch(somePath, someStem);
SomeMethodThatTakesANonNullableString(filePatternMatch.Stem); //No warning.
Alternative Designs
No response
Risks
I don't think this is a breaking change on its own, but if we decided to also add an ArgumentNullException
if the constructor receives a null
stem it would be.