public class ModelConvertHelper<T>where T: new() { public static IList<T> ConvertToModel(DataTable dt) { IList<T> list = 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)) { if (!pi.CanWrite) { continue; } object value = dr[tempName]; if (value != DBNull.Value) { pi.SetValue(t, value, null); } } } list.Add(t); } return list; } }