public List<T> getClsslist<T>(SQLNewsModel sqlmodel)
{
List<T> list = new List<T>();
DataTable dtlist = null;
T model = default(T);
if (dtlist.Rows.Count > 0)
{
model = Activator.CreateInstance<T>();
foreach (DataRow dr in dtlist.Rows)
{
foreach (DataColumn dc in dr.Table.Columns)
{
object drValue = dr[dc.ColumnName];
PropertyInfo pi = model.GetType().GetProperty(dc.ColumnName);
if (pi != null && pi.CanWrite && (drValue != null && !Convert.IsDBNull(drValue)))
{
pi.SetValue(model, drValue, null);
}
}
list.Add(model);
}
}
else
list = null;
return list;
}
网友评论