Files
ww-jst/wmsjst/JSMachine.WMS.Infrastructure/Extensions/EnumerableExtensions.cs
T

44 lines
1.2 KiB
C#
Raw Normal View History

2026-09-02 16:31:50 +08:00
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;
}
}
}