public DataTable ToDataTables<T>(IList<T> data)
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
for (int i = 0; i < props.Count;i++ )
{
PropertyDescriptor prp = props[i];
table.Columns.Add(prp.Name,prp.PropertyType);
}
object[] values = new object[props.Count];
foreach(T item in data)
{
for (int i = 0; i < values.Length;i++ )
{
values[i] = props[i].GetValue(item);
}
table.Rows.Add(values);
}
return table;
}