public static tdsReport.PurchaseDataTable ToDataTable<t>(this IList<t> data) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(t)); DataTable DT = new DataTable(); foreach (PropertyDescriptor prop in properties) { DT.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); foreach (T item in data) { DataRow row = DT.NewRow(); foreach (PropertyDescriptor prop2 in properties) row[prop2.Name] = prop2.GetValue(item) ?? DBNull.Value; DT.Rows.Add(row); } } return DT as tdsReport.PurchaseDataTable; }