using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; namespace DS.Pro.code { public class DataTableEntity { public static IList GetEntities(DataTable table) where T : new() { IList entities = new List(); foreach (DataRow row in table.Rows) { T entity = new T(); foreach (var item in entity.GetType().GetProperties()) { if (table.Columns.Contains(item.Name)) { if (DBNull.Value != row[item.Name]) { item.SetValue(entity, row[item.Name], null); } } } entities.Add(entity); } return entities; } } }