topher-b
7/15/2015 - 5:12 PM

Reflection

Reflection

foreach (InventoryJson item in jsonData)
{
  List<object> values = new List<object>();
  foreach (PropertyInfo property in typeof(InventoryJson).GetProperties(BindingFlags.Public | BindingFlags.Instance))
  {
    values.Add(property.GetValue(item,null));
  }
  dataToDisplay.Rows.Add(values.ToArray());
}
foreach (PropertyInfo property in typeof(InventoryJson).GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
  DataColumn column = new DataColumn { DataType = Type.GetType("System.String"), ColumnName = property.Name };
  dataToDisplay.Columns.Add(column);
}