using System.Collections; namespace adas_core.Domain.Utils; public static class CollectionsUtils { public static bool IsNullOrEmpty(this List? value) { return value == null || !value.Any(); } public static bool IsEmptyOrNull(List? value) { return value == null || !value.Any(); } public static bool HasElements(List? value) { return value != null && value.Any(); } public static bool IsNotEmpty(List value) { return !IsEmptyOrNull(value); } public static List EmptyIfNull(List? value) { return value ?? []; } public static List? NullIfEmpty(List value) { return IsEmptyOrNull(value) ? null : value; } public static Array ToArray(ICollection collection, Type type) { var result = Array.CreateInstance(type, collection.Count); collection.CopyTo(result, 0); return result; } public static List IfEmptyOrNull(List list, List defaultList) { return IsEmptyOrNull(list) ? defaultList : list; } }