Use Lambda or Expression To Specify Property to Get Via Reflection
I have a prototype method for fetching a named property value from a model object:
I would like to avoid the caller having to provide the property name as a string, and instead somehow use a delegate, or some sort of expression construct, to specify an actual property on
Then I can either use the delegate to fetch the property value, or at least reflect on the delegate to get the property name and then again use reflection to get the property value.
What ways can I go about this?
I would like to avoid the caller having to provide the property name as a string, and instead somehow use a delegate, or some sort of expression construct, to specify an actual property on
dbModel, where it would be called something like:Then I can either use the delegate to fetch the property value, or at least reflect on the delegate to get the property name and then again use reflection to get the property value.
What ways can I go about this?