I have a C# class that I want to loop through the properties as a key/value pair but don’t know how.
Here is what I would like to do:
Foreach (classobjectproperty prop in classobjectname)
{
if (prop.name == "somename")
//do something cool with prop.value
}
Yup:
This won’t give them as key/value pairs, but you can get all kinds of information from a
PropertyInfo.Note that this will only give public properties. For non-public ones, you’d want to use the overload which takes a
BindingFlags. If you really want just name/value pairs for instance properties of a particular instance, you could do something like: