So I need to access a class property's value dynamically at runtime but I can't figure out how to do this...any suggestions? Thanks!
//Works
int Order = OrdersEntity.ord_num;
//I would love for this to work.. it obviously does not.
string field_name = "ord_num";
int Order = OrdersEntity.(field_name);
OK so here is what I have so far with reflection, which balks unless the collection item it is looping through is a string:
void RefreshGrid(EntityCollection<UOffOrdersStgEcommerceEntity> collection)
{
List<string> col_list = new List<string>();
foreach (UOffOrdersStgEcommerceEntity rec in collection)
{
foreach (System.Collections.Generic.KeyValuePair<string, Dictionary<string, string>> field in UOffOrdersStgEcommerceEntity.FieldsCustomProperties)
{
if (!string.IsNullOrEmpty((string)rec.GetType().GetProperty(field.Key).GetValue(rec, null)))
{
if (!col_list.Contains<string>((string)rec.GetType().GetProperty(field.Key).GetValue(rec, null)))
col_list.Add((string)rec.GetType().GetProperty(field.Key).GetValue(rec,null));
}
}
foreach (string ColName in col_list)
{
grdOrders.Columns.Add(new DataGridTextColumn
{
Header = ColName,
Binding = new Binding(ColName)
});
}
}
grdOrders.ItemsSource = collection;
}