So I have response data from various API calls. Each of these calls returns a list of objects, and each object could also contain a list of objects. As there are many different object types the method will have to be generic. What I am aiming for is to have a data grid that contains the objects properties, and if the property is another list add a data grid control instead.
public static DataTable GetDataGrid(this IList list)
{
var dt = new DataTable();
foreach (var o in (IEnumerable)list)
{
var r = dt.NewRow();
foreach (var f in o.GetType().GetProperties())
{
if (!dt.Columns.Contains(f.Name))
{
dt.Columns.Add(f.Name);
}
var value = f.GetValue(o);
Type t = value.GetType();
// if it is an integer list just concat the values
if (value is IList<int?>)
{
r[f.Name] = (String.Join<int?>(",", (IEnumerable<int?>)value));
}// if it is another object list create a datagrid
else if (value is IList)
{
// CREATE A DATA GRID
}// if it is not a list just add the value
else
{
r[f.Name] = value;
}
}
dt.Rows.Add(r);
}
return dt;
}
This was how far I got, but this is also just a DataTable
EDIT: Example
So I would like the raw data underneath shown in the table. System Memory, Process Memory and GPU are all objects of differing types, but I would like them to be their own tables within the respective cells. If that is not possible could I store a trigger of some kind to open a table.