public class Foo
{
public string Bar {get; set;}
}
How do I get the value of Bar, a string property, via reflection? The following code will thr
the getvalue with object and null worked great for me. Thanks for the posts.
Context: Looping through all properties in an MVC model for New Hires and determining their form posted values:
newHire => the Model, with many properties, whose posted form values I want to write individually to a set of database records
foreach(var propertyValue in newHire.GetProperties())
{
string propName = propertyValue.Name;
string postedValue = newHire.GetType().GetProperty(propName).GetValue(newHire, null).ToString();
}