using JetBrains.Annotations; namespace VberZero.Tools; public static class CollectionExtensions { public static IList RemoveAll([NotNull] this ICollection source, Func predicate) { var items = source.Where(predicate).ToList(); foreach (var item in items) { source.Remove(item); } return items; } public static bool Empty(this ICollection source) { if (source != null) return source.Count <= 0; return true; } public static bool NotEmpty(this ICollection source) { return !Empty(source); } public static bool IsNullOrEmpty(this ICollection source) { if (source != null) return source.Count <= 0; return true; } public static bool AddIfNotContains(this ICollection source, T item) { if (source == null) throw new ArgumentNullException(nameof(source)); if (source.Contains(item)) return false; source.Add(item); return true; } }