看看代码生成器
public IList<T> GetList<T>(DataTable table)
{ IList<T> list = new List<T>();
T t = default(T);
PropertyInfo[] propertypes = null;
string tempName = string.Empty;
foreach (DataRow row in table.Rows)
{
t = Activator.CreateInstance<T>();
propertypes = t.GetType().GetProperties();
foreach (PropertyInfo pro in propertypes)
{
tempName = pro.Name;
if (table.Columns.Contains(tempName))
{
object value = row[tempName];
pro.SetValue(t, value, null);
} }
list.Add(t);
} return list;
}http://topic.csdn.net/u/20081218/16/9eaa37a4-a5fb-4288-a134-6ff68d2ffc7f.html
public IList<T> GetList<T>(DataTable table)
{ IList<T> list = new List<T>();
T t = default(T);
PropertyInfo[] propertypes = null;
string tempName = string.Empty;
foreach (DataRow row in table.Rows)
{
t = Activator.CreateInstance<T>();
propertypes = t.GetType().GetProperties();
foreach (PropertyInfo pro in propertypes)
{
tempName = pro.Name;
if (table.Columns.Contains(tempName))
{
object value = row[tempName];
pro.SetValue(t, value, null);
} }
list.Add(t);
} return list;
}http://topic.csdn.net/u/20081218/16/9eaa37a4-a5fb-4288-a134-6ff68d2ffc7f.html
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货