public static List<mYY_appointment_punishRec> ConvertToModel(DataTable dt)
{
List<mYY_appointment_punishRec> ts = new List<mYY_appointment_punishRec>();// 定义集合
Type type = typeof(mYY_appointment_punishRec); // 获得此模型的类型
string tempName = "";
foreach (DataRow dr in dt.Rows)
{
mYY_appointment_punishRec t = new mYY_appointment_punishRec();
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
foreach (PropertyInfo pi in propertys)
{
tempName = pi.Name;
if (dt.Columns.Contains(tempName))
{
if (!pi.CanWrite) continue;
object value = dr[tempName];
if (value != DBNull.Value)
pi.SetValue(t, value, null);
}
}
ts.Add(t);
}
return ts;
}
{
List<mYY_appointment_punishRec> ts = new List<mYY_appointment_punishRec>();// 定义集合
Type type = typeof(mYY_appointment_punishRec); // 获得此模型的类型
string tempName = "";
foreach (DataRow dr in dt.Rows)
{
mYY_appointment_punishRec t = new mYY_appointment_punishRec();
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
foreach (PropertyInfo pi in propertys)
{
tempName = pi.Name;
if (dt.Columns.Contains(tempName))
{
if (!pi.CanWrite) continue;
object value = dr[tempName];
if (value != DBNull.Value)
pi.SetValue(t, value, null);
}
}
ts.Add(t);
}
return ts;
}