From d6bedf20d43c1ec2ecd9ab6210d74a56f880949f Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Mon, 30 Sep 2024 17:18:46 +0200 Subject: [PATCH] added IsEmptyOrNull overloads to avoid type checks for faster implementation --- .../Extensions/IEnumerableExtensions.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Aardvark.Base/Extensions/IEnumerableExtensions.cs b/src/Aardvark.Base/Extensions/IEnumerableExtensions.cs index e8439ceb..a33ffec5 100644 --- a/src/Aardvark.Base/Extensions/IEnumerableExtensions.cs +++ b/src/Aardvark.Base/Extensions/IEnumerableExtensions.cs @@ -875,6 +875,26 @@ public static bool AllEqual(this IEnumerable elements) #region Comparisons + /// + /// Returns true if elements contains no items or if elements is null, + /// false otherwise. + /// + public static bool IsEmptyOrNull(this T[] elements) + { + if (elements == null) return true; + return elements.Length == 0; + } + + /// + /// Returns true if elements contains no items or if elements is null, + /// false otherwise. + /// + public static bool IsEmptyOrNull(this ICollection elements) + { + if (elements == null) return true; + return elements.Count == 0; + } + /// /// Returns true if elements contains no items or if elements is null, /// false otherwise.