CollectionHelper.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace TEAMModelOS.SDK
  6. {
  7. public static class CollectionHelper
  8. {
  9. /// <summary>
  10. /// 判断集合是否为空
  11. /// </summary>
  12. /// <param name="collection"></param>
  13. /// <returns></returns>
  14. public static bool IsEmpty<T>(this IEnumerable<T> collection)
  15. {
  16. if (collection != null && collection.Any())
  17. {
  18. return false;
  19. }
  20. else
  21. {
  22. return true;
  23. }
  24. }
  25. /// <summary>
  26. /// 判断集合是否不为空
  27. /// </summary>
  28. /// <param name="collection"></param>
  29. /// <returns></returns>
  30. public static bool IsNotEmpty<T>(this IEnumerable<T> collection)
  31. {
  32. if (collection != null && collection.Any())
  33. {
  34. return true;
  35. }
  36. else
  37. {
  38. return false;
  39. }
  40. }
  41. ///// <summary>
  42. ///// 判断集合是否为空
  43. ///// </summary>
  44. ///// <param name="collection"></param>
  45. ///// <returns></returns>
  46. //public static bool IsEmpty(this ICollection collection)
  47. //{
  48. // if (collection != null && collection.Count > 0)
  49. // {
  50. // return false;
  51. // }
  52. // else
  53. // {
  54. // return true;
  55. // }
  56. //}
  57. ///// <summary>
  58. ///// 判断集合是否不为空
  59. ///// </summary>
  60. ///// <param name="collection"></param>
  61. ///// <returns></returns>
  62. //public static bool IsNotEmpty(this ICollection collection)
  63. //{
  64. // if (collection != null && collection.Count > 0)
  65. // {
  66. // return true;
  67. // }
  68. // else
  69. // {
  70. // return false;
  71. // }
  72. //}
  73. }
  74. }