using System.Data.DataSetExtensions;
using System.Collections.Generic;
public static void Main()
DataTable dt = new DataTable();
for(int i=0;i<=1000;i++){dt.Rows.Add(i, "foo", 1.1, null, true, DateTime.Now);}
var typedList = DataTableToList<Class1>(dt);
Console.WriteLine("Spotchecking first value");
Console.WriteLine(typedList[0].foo);
Console.WriteLine(typedList[0].foo2);
Console.WriteLine(typedList[0].foo3);
Console.WriteLine(typedList[0].foo4);
public static List<T> DataTableToList<T>(DataTable table) where T : class, new()
var tType = tempT.GetType();
List<T> list = new List<T>();
foreach (var row in table.Rows.Cast<DataRow>())
foreach (var prop in obj.GetType().GetProperties())
var propertyInfo = tType.GetProperty(prop.Name);
var rowValue = row[prop.Name];
var t = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
object safeValue = (rowValue == null || DBNull.Value.Equals(rowValue)) ? null : Convert.ChangeType(rowValue, t);
propertyInfo.SetValue(obj, safeValue, null);
public string name {get;set;}
public Double foo {get;set;}
public int? foo2 {get;set;}
public bool foo3 {get;set;}
public DateTime foo4 {get;set;}