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