CollectionExtensions.cs 594 B

123456789101112131415161718192021222324252627282930
  1. namespace Long.Core.Extensions;
  2. public static class CollectionExtensions
  3. {
  4. public static bool IsNullOrEmpty<T>(this ICollection<T> source)
  5. {
  6. if (source != null)
  7. {
  8. return source.Count <= 0;
  9. }
  10. return true;
  11. }
  12. public static bool AddIfNotContains<T>(this ICollection<T> source, T item)
  13. {
  14. if (source == null)
  15. {
  16. throw new ArgumentNullException("source");
  17. }
  18. if (source.Contains(item))
  19. {
  20. return false;
  21. }
  22. source.Add(item);
  23. return true;
  24. }
  25. }