/// <summary>
/// TableToList
/// </summary>
public class TableListConverter<T> where T : class, new()
public static IList<T> TableToList(DataTable dt)
IList<T> ts = new List<T>();// 定义集合
Type type = typeof(T);// 获得此模型的类型
string tempName = "";
foreach (DataRow dr in dt.Rows)
T t = new T();
// 获得此模型的公共属性
PropertyInfo[] propertys = t.GetType().GetProperties();
foreach (PropertyInfo pi in propertys)
tempName = pi.Name;
if (dt.Columns.Contains(tempName))// 检查DataTable是否包含此列
if (!pi.CanWrite) continue;// 判断此属性是否有Setter
object value = dr[tempName];
if (value != DBNull.Value)
pi.SetValue(t, value, null);
ts.Add(t);
return ts;