Link to home
Start Free TrialLog in
Avatar of nmiller61
nmiller61

asked on

C# Find Property Name and then set the value of the property

I am trying to loop through a collection that has three fields in each row of the collection. I want to set the property of my view model based on one of the fields in my collection. See before for an example.

//Collection ViewModel
 public class TestSubmissionViewModel
    {
        public string label { get; set; }
        public string val { get; set; }
        public string fieldType { get; set; }
    }

//My view model I want to populate
public class MyViewModel
{
public string name {get; set;}
public string address {get; set;}
public string address1 {get; set;}
}

In my TestSubmissionViewModel collection I will have values like:
label = "name", val="TestUser", fieldtype="String"
label = "address", val="111 Test St", fieldtype=String"

So I want to loop there the TestSubmissionViewModel and match up the "label" field value to the property of the MyViewModel and then set the value of that property. How can I do this?
ASKER CERTIFIED SOLUTION
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial