Skip to content

[API Proposal]: FilePatternMatch.Stem should be made non-nullable. #116982

Open
@MitchBodmer

Description

@MitchBodmer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-Extensions-FileSystemuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions