public class DataTableHelper
{
#region DataTable转IList
///
/// DataTable转IList集合
///
///
///
///
public static IList
{
IList
if (dataTable != null)
{
foreach (DataRow dr in dataTable.Rows)
{
T t = new T();
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
foreach (PropertyInfo pi in propertys)
{
var name = pi.Name;
if (dataTable.Columns.Contains(name))
{
if (!pi.CanWrite) continue;
object value = dr[name];
if (value != DBNull.Value)
{
pi.SetValue(t, value, null);
}
}
}
list.Add(t);
}
}
return list;
}
#endregion
}