34 lines
900 B
C#
34 lines
900 B
C#
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<T> GetEntities<T>(DataTable table) where T : new()
|
|
{
|
|
IList<T> entities = new List<T>();
|
|
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;
|
|
}
|
|
|
|
}
|
|
} |