using System.Collections;
namespace Soul2.General.utils {
public static class CollectionsUtils {
///
/// 判断非空
///
/// 集合对象
/// 是否非空
public static bool isNotEmpty(this IEnumerable collection) {
return !isEmpty(collection);
}
///
/// 判断为空
///
/// 集合对象
/// 是否为空
public static bool isEmpty(this IEnumerable collection) {
if (collection == null) {
return true;
}
foreach (var item in collection) {
return false;
}
return true;
}
///
/// 去重
///
///
///
///
public static List duplicateRemoval(this List list) {
if (list.isNotEmpty()) {
var set = new HashSet(list);
return new List(set);
} else {
return list;
}
}
public static HashSet toSet(this IEnumerable collection) {
return new HashSet(collection);
}
}
}