Advertisement
Iyon_Groznyy

Untitled

Jul 1st, 2022
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. public static class CollectionExtensions
  2.     {
  3.         public static bool IsNullOrEmpty<T>(this IEnumerable<T> items)
  4.         {
  5.             return items == null || !items.Any();
  6.         }
  7.  
  8.         public static bool IsNotNullNorEmpty<T>(this IEnumerable<T> items)
  9.         {
  10.             return items != null && items.Any();
  11.         }
  12.  
  13.         public static bool IsEmpty(this IEnumerable collection)
  14.         {
  15.             var enumerator = collection.GetEnumerator();
  16.             var isEmpty = !enumerator.MoveNext();
  17.             return isEmpty;
  18.         }
  19.  
  20.         public static bool IsNotEmpty(this IEnumerable collection)
  21.         {
  22.             return !IsEmpty(collection);
  23.         }
  24.  
  25.         public static bool IsEmpty(this ICollection collection)
  26.         {
  27.             return collection.Count == 0;
  28.         }
  29.  
  30.         public static bool IsNotEmpty(this ICollection collection)
  31.         {
  32.             return !IsEmpty(collection);
  33.         }
  34.  
  35.         public static bool IsNullOrEmpty(this IEnumerable collection)
  36.         {
  37.             return collection is null || IsEmpty(collection);
  38.         }
  39.  
  40.         public static bool IsNotNullNorEmpty(this IEnumerable collection)
  41.         {
  42.             return !IsNullOrEmpty(collection);
  43.         }
  44.  
  45.         public static bool IsNullOrEmpty(this ICollection collection)
  46.         {
  47.             return collection is null || IsEmpty(collection);
  48.         }
  49.  
  50.         public static bool IsNotNullNorEmpty(this ICollection collection)
  51.         {
  52.             return !IsNullOrEmpty(collection);
  53.         }
  54.  
  55.         public static void AddRange<T>(this ObservableCollection<T> collection, IEnumerable<T> items)
  56.         {
  57.             foreach (var item in items)
  58.             {
  59.                 collection.Add(item);
  60.             }
  61.         }
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement