44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Linq;
|
|
using JSMachine.DCS.Infrastructure;
|
|
using JSMachine.WMS.Infrastructure;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace System.Collections.Generic
|
|
{
|
|
public static class EnumerableExtensions
|
|
{
|
|
public static void ForEach<T>(this IEnumerable<T> @this, Action<T> callback, bool immutable = false)
|
|
{
|
|
Guards.ThrowIfNull(@this, callback);
|
|
|
|
var collection = immutable ? @this.ToArray() : @this;
|
|
|
|
foreach (T item in collection)
|
|
{
|
|
callback(item);
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<T> Do<T>(this IEnumerable<T> @this, Action<T> callback)
|
|
{
|
|
Guards.ThrowIfNull(@this, callback);
|
|
|
|
foreach (var item in @this)
|
|
{
|
|
callback?.Invoke(item);
|
|
yield return item;
|
|
}
|
|
}
|
|
|
|
//public static bool IsNullOrEmpty<T>(this IEnumerable<T> source)
|
|
//{
|
|
// return source == null || source.Count() == 0;
|
|
//}
|
|
|
|
public static bool IsNullOrEmpty(this IList source)
|
|
{
|
|
return source == null || source.Count == 0;
|
|
}
|
|
}
|
|
}
|