I try to code a common method to fill in an class object list with datatable as following:
public static List FillDataTable(object obj, DataTable dt)
{
List objList = new List();
object o = new object(); //how to declare this instance based on the object obj???
foreach (DataRow dr in dt.Rows)
{
//code to fill datarow to the object o
objList.Add(o);
}
return objList;
}
Call this method as followiing:
List lstObj = new List();
lstObj = FillDataTable(((object)new myClass()), dt).OfType().ToList();