|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
using System; |
|
|
|
|
using Microsoft.VisualBasic; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
@ -6,13 +7,13 @@ using System.Text; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
namespace Soul2.General.utils { |
|
|
|
|
public class CollectionsUtils { |
|
|
|
|
public static class CollectionsUtils { |
|
|
|
|
/// <summary> |
|
|
|
|
/// 判断非空 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="collection">集合对象</param> |
|
|
|
|
/// <returns>是否非空</returns> |
|
|
|
|
public static bool isNotEmpty(IEnumerable collection) { |
|
|
|
|
public static bool isNotEmpty(this IEnumerable collection) { |
|
|
|
|
return !isEmpty(collection); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -21,7 +22,7 @@ namespace Soul2.General.utils { |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="collection">集合对象</param> |
|
|
|
|
/// <returns>是否为空</returns> |
|
|
|
|
public static bool isEmpty(IEnumerable collection) { |
|
|
|
|
public static bool isEmpty(this IEnumerable collection) { |
|
|
|
|
if (collection == null) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -30,5 +31,24 @@ namespace Soul2.General.utils { |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 去重 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <typeparam name="T"></typeparam> |
|
|
|
|
/// <param name="list"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public static List<T> duplicateRemoval<T>(this List<T> list) { |
|
|
|
|
if (list.isNotEmpty()) { |
|
|
|
|
var set = new HashSet<T>(list); |
|
|
|
|
return new List<T>(set); |
|
|
|
|
} else { |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static HashSet<T> toSet<T>(this IEnumerable<T> collection) { |
|
|
|
|
return new HashSet<T>(collection); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|