如何将 DataTable 转成 IEnumerable<T> ?
public static List<T> ConvertDataTableToGenericList<T>(DataTable dt) { var columnNames = dt.Columns.Cast<DataColumn>() .Select(c => c.ColumnName) .ToList(); var properties = typeof(T).GetProperties(); DataRow[] rows= dt.Select(); return rows.Select(row => { var objT = Activator.CreateInstance<T>(); foreach (var pro in properties) { if (columnNames.Contains(pro.Name)) pro.SetValue(objT, row[pro.Name]); } return objT; }).ToList(); }