Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/GuardClauses/GuardAgainstNullExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ public static IEnumerable<T> NullOrEmpty<T>(this IGuardClause guardClause,
#endif
{
Guard.Against.Null(input, parameterName, message);
if (!input.Any())

if (input is Array and { Length: 0 } //Try checking first with pattern matching because it's faster than TryGetNonEnumeratedCount on Array
#if NET6_0_OR_GREATER
|| (input.TryGetNonEnumeratedCount(out var count) && count == 0)
#endif
|| !input.Any())
{
throw new ArgumentException(message ?? $"Required input {parameterName} was empty.", parameterName);
}
Expand Down