Skip to content

Commit 4fe9af0

Browse files
JamieMageeCopilot
andcommitted
chore: use ArgumentNullException.ThrowIfNull where applicable
Replace pre-.NET 6 throw new ArgumentNullException(nameof(x)) patterns with ArgumentNullException.ThrowIfNull(x). Sites with custom exception messages are left unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 87ae1f8 commit 4fe9af0

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/Microsoft.ComponentDetection.Common/PatternMatchingUtility.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public sealed class CompiledMatcher
6161
private readonly string[] patterns;
6262

6363
public CompiledMatcher(IEnumerable<string> patterns)
64-
: this(patterns is string[] arr ? arr : (patterns ?? throw new ArgumentNullException(nameof(patterns))).ToArray())
64+
: this(ToArray(patterns))
6565
{
6666
}
6767

@@ -72,6 +72,12 @@ internal CompiledMatcher(string[] patterns)
7272
ValidatePatternElements(this.patterns);
7373
}
7474

75+
private static string[] ToArray(IEnumerable<string> patterns)
76+
{
77+
ArgumentNullException.ThrowIfNull(patterns);
78+
return patterns as string[] ?? patterns.ToArray();
79+
}
80+
7581
public bool IsMatch(ReadOnlySpan<char> fileName) => GetFirstMatchingPattern(fileName, this.patterns) is not null;
7682

7783
/// <summary>

0 commit comments

Comments
 (0)