using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace Pcb.Common
|
{
|
/// <summary>
|
/// 列表扩展
|
/// </summary>
|
/// <typeparam name="T"></typeparam>
|
public static class extEnumerable
|
{
|
#region 转换成散列集合
|
/// <summary>
|
/// 转换成HashSet
|
/// </summary>
|
/// <typeparam name="T">列表项类型</typeparam>
|
/// <param name="List">枚举列表</param>
|
/// <returns>HashSet</returns>
|
public static HashSet<T> _ToHashSet<T>(this IEnumerable<T> List)
|
{
|
var hs = new HashSet<T>();
|
foreach (var i in List) { hs.Add(i); }
|
return hs;
|
}
|
/// <summary>
|
/// 转换成HashSet
|
/// </summary>
|
/// <typeparam name="T">列表项类型</typeparam>
|
/// <param name="List">枚举列表</param>
|
/// <returns>HashSet</returns>
|
public static HashSet<T> _ToHashSet<T>(this IEnumerable List)
|
{
|
var hs = new HashSet<T>();
|
foreach (T i in List) { hs.Add(i); }
|
return hs;
|
}
|
/// <summary>
|
/// 转换成HashSet
|
/// </summary>
|
/// <typeparam name="T">列表项类型</typeparam>
|
/// <typeparam name="TValue">其它类型</typeparam>
|
/// <param name="List">枚举列表</param>
|
/// <param name="Select">选择键函数</param>
|
/// <returns>数组</returns>
|
public static HashSet<TValue> _ToHashSet<T, TValue>(this IEnumerable<T> List, Func<T, TValue> Select)
|
{
|
var hs = new HashSet<TValue>();
|
foreach (var i in List) { hs.Add(Select(i)); }
|
return hs;
|
}
|
/// <summary>
|
/// 转换成HashSet
|
/// </summary>
|
/// <typeparam name="T">列表项类型</typeparam>
|
/// <typeparam name="TValue">其它类型</typeparam>
|
/// <param name="List">枚举列表</param>
|
/// <param name="Select">选择键函数</param>
|
/// <returns>数组</returns>
|
public static HashSet<TValue> _ToHashSet<T, TValue>(this IEnumerable List, Func<T, TValue> Select)
|
{
|
var hs = new HashSet<TValue>();
|
foreach (T i in List) { hs.Add(Select(i)); }
|
return hs;
|
}
|
/// <summary>
|
/// 转换成其它类型列表
|
/// </summary>
|
/// <typeparam name="TValue">其它类型</typeparam>
|
/// <param name="List">数据行列表</param>
|
/// <param name="Select">选择键函数</param>
|
/// <returns>列表</returns>
|
public static HashSet<TValue> _ToHashSet<TValue>(this System.Data.DataRowCollection List, Func<System.Data.DataRow, TValue> Select)
|
{
|
HashSet<TValue> lst = new HashSet<TValue>();
|
foreach (System.Data.DataRow i in List) { lst.Add(Select(i)); }
|
return lst;
|
}
|
/// <summary>
|
/// 转换成其它类型列表
|
/// </summary>
|
/// <typeparam name="TValue">其它类型</typeparam>
|
/// <param name="List">数据行列表</param>
|
/// <param name="Select">选择键函数</param>
|
/// <returns>列表</returns>
|
public static HashSet<TValue> _ToHashSet<TValue>(this System.Data.DataColumnCollection List, Func<System.Data.DataColumn, TValue> Select)
|
{
|
HashSet<TValue> lst = new HashSet<TValue>();
|
foreach (System.Data.DataColumn i in List) { lst.Add(Select(i)); }
|
return lst;
|
}
|
#endregion
|
}
|
}
|