first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user