I've got an object array of Key values.
public class KeyValueStore
{
public string Key {get;set;}
public string Value {get;set;}
}
This array stores the values of an object i am trying to fill like this:
public class Customer
{
public string Name {get;set;}
public string Country {get;set}
}
So i want to map these keys from KeyValueStore to Customer properties
public Customer TransformToCustomer(KeyValueStore[] keyValueStore)
{
var customer = new Customer();
foreach (var keyValue in keyValueStore)
{
switch (keyValue.Key)
{
case "Name":
customer.Name = keyValue.Value;
break;
case "Cntry":
customer.Country = keyValue.Value;
break;
}
}
return customer;
}
Is there a better way to do this?