33 lines
798 B
C#
33 lines
798 B
C#
namespace DD.Persistence.Repository.Extensions;
|
|
|
|
public static class IEnumerableExtensions
|
|
{
|
|
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
|
{
|
|
if (source == null)
|
|
throw new ArgumentNullException(nameof(source));
|
|
if (action == null)
|
|
throw new ArgumentNullException(nameof(action));
|
|
|
|
foreach (var item in source)
|
|
{
|
|
action(item);
|
|
}
|
|
}
|
|
|
|
public static bool IsNullOrEmpty<T>(this IEnumerable<T>? enumerable)
|
|
{
|
|
if (enumerable == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
var collection = enumerable as ICollection<T>;
|
|
if (collection != null)
|
|
{
|
|
return collection.Count < 1;
|
|
}
|
|
return !enumerable.Any();
|
|
}
|
|
}
|