Creado apartir del commit b888de6c92056de294456f581a56e25e734d4ab7 de develop
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace adas_core.Domain.Utils;
|
||||
|
||||
public static class CollectionsUtils
|
||||
{
|
||||
public static bool IsNullOrEmpty<T>(this List<T>? value)
|
||||
{
|
||||
return value == null || !value.Any();
|
||||
}
|
||||
|
||||
public static bool IsEmptyOrNull<T>(List<T>? value)
|
||||
{
|
||||
return value == null || !value.Any();
|
||||
}
|
||||
|
||||
public static bool HasElements<T>(List<T>? value)
|
||||
{
|
||||
return value != null && value.Any();
|
||||
}
|
||||
|
||||
public static bool IsNotEmpty<T>(List<T> value)
|
||||
{
|
||||
return !IsEmptyOrNull(value);
|
||||
}
|
||||
|
||||
public static List<T> EmptyIfNull<T>(List<T>? value)
|
||||
{
|
||||
return value ?? [];
|
||||
}
|
||||
|
||||
public static List<T>? NullIfEmpty<T>(List<T> 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<string> IfEmptyOrNull(List<string> list, List<string> defaultList)
|
||||
{
|
||||
return IsEmptyOrNull(list) ? defaultList : list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user