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.
49 lines
1.1 KiB
49 lines
1.1 KiB
using OT.COM.ArsenalDB;
|
|
using OT.COM.LogisticsUtil;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
namespace CounsellorBL.Helper
|
|
{
|
|
public static class EntityHelper
|
|
{
|
|
public static List<T> FromDataTable<T>(List<DataRow> i_dt) where T : EntityBase, new()
|
|
{
|
|
List<T> lRes = new List<T>();
|
|
|
|
if (i_dt != null && i_dt.Any())
|
|
{
|
|
|
|
|
|
PropertyInfo[] pis = typeof(T).GetProperties();
|
|
|
|
DataColumnCollection dcc = i_dt[0].Table.Columns;
|
|
|
|
|
|
|
|
foreach (DataRow dr in i_dt)
|
|
{
|
|
T tCur = new T();
|
|
|
|
foreach (PropertyInfo pi in pis)
|
|
{
|
|
if (!dcc.Contains(pi.Name) || dr[pi.Name] is DBNull)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
ClassHelper.SetValueByPropertyName(tCur, pi.Name, dr[pi.Name]);
|
|
}
|
|
|
|
|
|
lRes.Add(tCur);
|
|
}
|
|
}
|
|
|
|
return lRes;
|
|
}
|
|
}
|
|
}
|