I have an object which has a huge number of properties. I'd like to get the value of each of those properties by simply looping through the properties collection of the object.
I've looked into the PropertyInfo.GetValue() method however it's not making much sense in the context I have.
Here's an example of what i'm trying to do (this code doesn't work btw):
foreach(var item in dataObjects)
{
foreach(PropertyInfo prop in item.GetType().GetProperties())
{
String value = prop.GetValue().ToString()
}
}
I realise now that getting the value of a property isn't this easy. What am I missing? I don't really understand what I need to pass to the GetValue() method because I simply want the value of the property I'm calling that method on.
Thanks for any help clarifying this for me. I've spent a couple of hours here just banging my head against the desk.