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.
 
 

45 lines
1.0 KiB

using System.Collections;
using System.Data;
using System.Reflection;
namespace EC.Utils
{
/// <summary>
/// ExtHashtable
/// 版 本:V3.0.0
/// 版 权:EasyCode
/// 作 者:LXC
/// </summary>
public static class ExtHashtable
{
/// <summary>
/// 实体转换Hashtable
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <param name="entity"></param>
/// <returns></returns>
public static Hashtable ToHashtable<TEntity>(this TEntity entity)
{
Hashtable ht = new Hashtable();
PropertyInfo[] ps = entity.GetType().GetProperties();
foreach (PropertyInfo i in ps)
{
ht[i.Name] = i.GetValue(entity, null);
}
return ht;
}
/// <summary>
/// DataRow 转 HashTable
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
public static Hashtable ToHashtable(this DataRow dr)
{
Hashtable htReturn = new Hashtable(dr.ItemArray.Length);
foreach (DataColumn dc in dr.Table.Columns)
htReturn.Add(dc.ColumnName, dr[dc.ColumnName]);
return htReturn;
}
}
}