You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
using Microsoft.VisualBasic;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Soul2.General.utils {
|
|
public static class CollectionsUtils {
|
|
/// <summary>
|
|
/// 判断非空
|
|
/// </summary>
|
|
/// <param name="collection">集合对象</param>
|
|
/// <returns>是否非空</returns>
|
|
public static bool isNotEmpty(this IEnumerable collection) {
|
|
return !isEmpty(collection);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断为空
|
|
/// </summary>
|
|
/// <param name="collection">集合对象</param>
|
|
/// <returns>是否为空</returns>
|
|
public static bool isEmpty(this IEnumerable collection) {
|
|
if (collection == null) {
|
|
return true;
|
|
}
|
|
foreach (var item in collection) {
|
|
return false;
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|