ListTool.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //************************************************************************
  2. // https://github.com/yuzhengyang
  3. // author: yuzhengyang
  4. // date: 2017.3.29 - 2017.9.12
  5. // desc: 元素列表工具类
  6. // Copyright (c) yuzhengyang. All rights reserved.
  7. //************************************************************************
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using Y.Utils.YUtils;
  12. namespace Y.Utils.DataUtils.Collections
  13. {
  14. /// <summary>
  15. /// 元素列表工具类
  16. /// </summary>
  17. public sealed class ListTool
  18. {
  19. /// <summary>
  20. /// 列表为空(null 或 count 等于 0)
  21. /// </summary>
  22. /// <typeparam name="T">元素类型</typeparam>
  23. /// <param name="list">元素列表</param>
  24. /// <returns></returns>
  25. [Obsolete("Please Use HasElements(list)", false)]
  26. public static bool IsNullOrEmpty<T>(IEnumerable<T> list)
  27. {
  28. YUtilsAuth.Check();
  29. if (list != null && list.Count() > 0)
  30. return false;
  31. return true;
  32. }
  33. /// <summary>
  34. /// 列表至少有一个元素
  35. /// </summary>
  36. /// <typeparam name="T">元素类型</typeparam>
  37. /// <param name="list">元素列表</param>
  38. /// <returns></returns>
  39. public static bool HasElements<T>(IEnumerable<T> list)
  40. {
  41. return !IsNullOrEmpty(list);
  42. }
  43. }
  44. }