diff --git a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/FilePatternMatch.cs b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/FilePatternMatch.cs index e19649700e322c..87d3954ef41292 100644 --- a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/FilePatternMatch.cs +++ b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/FilePatternMatch.cs @@ -28,16 +28,17 @@ public struct FilePatternMatch : IEquatable /// If the matcher searched for "src/Project/**/*.cs" and the pattern matcher found "src/Project/Interfaces/IFile.cs", /// then = "Interfaces/IFile.cs" and = "src/Project/Interfaces/IFile.cs". /// - public string? Stem { get; } + public string Stem { get; } /// /// Initializes new instance of /// /// The path to the file matched, relative to the beginning of the matching search pattern. /// The subpath to the file matched, relative to the first wildcard in the matching search pattern. - public FilePatternMatch(string path, string? stem) + public FilePatternMatch(string path, string stem) { ArgumentNullException.ThrowIfNull(path); + ArgumentNullException.ThrowIfNull(stem); Path = path; Stem = stem; diff --git a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternTestResult.cs b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternTestResult.cs index d1067b28574e41..4005fdc13ffa81 100644 --- a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternTestResult.cs +++ b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Internal/PatternTestResult.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace Microsoft.Extensions.FileSystemGlobbing.Internal { /// @@ -11,6 +13,7 @@ public struct PatternTestResult { public static readonly PatternTestResult Failed = new(isSuccessful: false, stem: null); + [MemberNotNullWhen(returnValue: true, nameof(Stem))] public bool IsSuccessful { get; } public string? Stem { get; } diff --git a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FilePatternMatchTests.cs b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FilePatternMatchTests.cs index c16e991e3b111c..f352c27013b2fe 100644 --- a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FilePatternMatchTests.cs +++ b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FilePatternMatchTests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using Xunit; namespace Microsoft.Extensions.FileSystemGlobbing.Tests @@ -24,5 +25,17 @@ public void TestGetHashCode() FilePatternMatch matchCase2 = new FilePatternMatch("sub/sub2/bar/baz/three.txt", "Sub2/bar/baz/thrEE.txt"); Assert.Equal(matchCase1.GetHashCode(), matchCase2.GetHashCode()); } + + [Fact] + public void TestPathArgumentNullExceptions() + { + Assert.Throws(() => new FilePatternMatch(null, "sub2/bar/baz/three.txt")); + } + + [Fact] + public void TestStemArgumentNullExceptions() + { + Assert.Throws(() => new FilePatternMatch("sub2/bar/baz/three.txt", null)); + } } }