I am trying to get the value out of a PropertyInfo without knowing what type it is at runtime.
private TreeViewItem processObject(string h,PropertyInfo o)
{
TreeViewItem root = new TreeViewItem();
root.Header = h;
Type myType = o.PropertyType;
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
foreach (PropertyInfo prop in props)
{
Type subType = o.GetType();
TreeViewItem sub = new TreeViewItem();
sub.Header = prop.Name + " : " + prop.GetValue(subType, null);
root.Items.Add(sub);
}
return root;
}
I am unsure of what yo pass into the prop.GetValue method in order to get out its value
Aucun commentaire:
Enregistrer un commentaire