using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace AntDesign { public static class EnumerableExtensions { public static void ForEach(this IEnumerable items, Action action) { if (items == null) { return; } foreach (T obj in items) { action(obj); } } public static async Task ForEachAsync(this IEnumerable items, Func func) { if (items == null) { return; } foreach (var item in items) await func(item); } public static bool IsIn(this T source, params T[] array) { if (array == null) { return false; } return array.Contains(source); } public static bool IsIn(this T source, IEnumerable array) { if (array == null) { return false; } return array.Contains(source); } public static T[] Append(this T[] array, T item) { if (array == null) { return new[] { item }; } Array.Resize(ref array, array.Length + 1); array[^1] = item; return array; } public static T[] Remove(this T[] array, T item) { if (array == null) { return Array.Empty(); } if (item == null) { return array.Where(x => x != null).ToArray(); } return array.Where(x => !item.Equals(x)).ToArray(); } } }