I have a class that converts a T List into a DataTable. And my problem is that I can not get the elements from the generic List T. T can be any model from entityFramework, like:
public class Test
{
public string userId { get; set; }
public string email { get; set; }
public string name { get; set; }
}
So List T is equivalent to List Test
My code is:
public class ConvertListToDataTable<T>
{
public T Field;
public DataTable ConvertTest<T>(List<T> item)
{
DataTable dT = new DataTable();
foreach(T t in item)
{
// here I want to get the elements from T and put them into the DataTable
}
return dT;
}
}
I know how to procces the dataTable, but I don't know how to get the 'userId', 'email', 'name' from the list