code block for converting a data table to generic list of custom class object.

public static List<T> ToList<T>(this DataTable table) where T : class, new()
    var list = new List<T>();
    foreach (var row in table.AsEnumerable())
        var obj = new T();
        foreach (var prop in obj.GetType().GetProperties())
            var propertyInfo = obj.GetType().GetProperty(prop.Name);
            propertyInfo.SetValue(obj, Convert.ChangeType(row[prop.Name], propertyInfo.PropertyType), null);


    return list;
10 X 5
** To prevent abusing comments from publishing, posted comments will be reviewed and then published!
 Mritunjay Kumar
Works at Mindfire Solutions

I mostly work with C#, ASP.NET, MVC, WCF, Web API, Entity FrameWork, MS Sql.

More under this category...
Extension method to convert a delimited string to list of generic primitive type
Convert generic list to data table
Generate random string from set of fixed chars
Google cloud storage API - Rename a file
Initializing X509Certificate2, Windows 2012 + IIS8 + .Net 4.5
Google cloud storage API - upload file with progress bar
Google cloud storage API - download file with progress bar
All under this category...