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 FromDataTable(List i_dt) where T : EntityBase, new() { List lRes = new List(); 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; } } }