I am not sure how to word this question properly, so apologies at the very beginning.
I am working with MongoDb and at some point, I need to design a lambda expression as follows:
...Set(g => g.Profile.First_Name, "Test");
Now, g
refers to a class called User
, which has a property of type Profile
(a different class), with the same name Profile
. As you can see, in the lambda expression, I am selecting the First_Name
property and then passing the value "Test"
to it.
My Question: Is there a way to select the property by name?
In more detail - is something like this possible? :
.... g.Profile. ("First_Name")
As I am typing this, even to me it sounds ridiculous, but I need to dynamically select the particular properties therefore I need to select them via their names.
How do I actually achieve this?
I tried :
g.Profile.GetType().GetProperty("First_Name")
But it doesn't seem to be equivalent to g.Profile.First_Name
.
Any ideas on what can be done?