Skip to content

Commit

Permalink
added IsEmptyOrNull overloads to avoid type checks for faster impleme…
Browse files Browse the repository at this point in the history
…ntation
  • Loading branch information
luithefirst committed Sep 30, 2024
1 parent 7610f16 commit d6bedf2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Aardvark.Base/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,26 @@ public static bool AllEqual<T>(this IEnumerable<T> elements)

#region Comparisons

/// <summary>
/// Returns true if elements contains no items or if elements is null,
/// false otherwise.
/// </summary>
public static bool IsEmptyOrNull<T>(this T[] elements)
{
if (elements == null) return true;
return elements.Length == 0;
}

/// <summary>
/// Returns true if elements contains no items or if elements is null,
/// false otherwise.
/// </summary>
public static bool IsEmptyOrNull<T>(this ICollection<T> elements)
{
if (elements == null) return true;
return elements.Count == 0;
}

/// <summary>
/// Returns true if elements contains no items or if elements is null,
/// false otherwise.
Expand Down

0 comments on commit d6bedf2

Please sign in to comment.