ListTool.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //############################################################
  2. // https://github.com/yuzhengyang
  3. // author:yuzhengyang
  4. //############################################################
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace Y.Utils.DataUtils.Collections
  8. {
  9. public sealed class ListTool
  10. {
  11. /// <summary>
  12. /// 列表为空(null 或 count 等于 0)
  13. /// </summary>
  14. /// <param name="list"></param>
  15. /// <returns></returns>
  16. public static bool IsNullOrEmpty(List<string> list)
  17. {
  18. if (list != null && list.Count() > 0)
  19. return false;
  20. return true;
  21. }
  22. /// <summary>
  23. /// 列表为空(null 或 count 等于 0)
  24. /// </summary>
  25. /// <typeparam name="T"></typeparam>
  26. /// <param name="list"></param>
  27. /// <returns></returns>
  28. public static bool IsNullOrEmpty<T>(List<T> list)
  29. {
  30. if (list != null && list.Count() > 0)
  31. return false;
  32. return true;
  33. }
  34. /// <summary>
  35. /// 列表为空(null 或 count 等于 0)
  36. /// </summary>
  37. /// <typeparam name="T"></typeparam>
  38. /// <param name="list"></param>
  39. /// <returns></returns>
  40. public static bool IsNullOrEmpty<T>(IEnumerable<T> list)
  41. {
  42. if (list != null && list.Count() > 0)
  43. return false;
  44. return true;
  45. }
  46. /// <summary>
  47. /// 列表至少有一个元素
  48. /// </summary>
  49. /// <typeparam name="T"></typeparam>
  50. /// <param name="list"></param>
  51. /// <returns></returns>
  52. public static bool HasElements<T>(IEnumerable<T> list)
  53. {
  54. return !IsNullOrEmpty(list);
  55. }
  56. }
  57. }