I Need to map a generic key value list to my model class.
Below is the KeyValues
class.
public class KeyValues
{
public string Key { get; }
public string Value { get; set; }
}
Getting this as input in IList<KeyValues>
with below values
Key = "SystemId"
Value = "12"
Key = "SystemName"
Value = "LTPVBN21"
Key = "Location"
Value = "NJ2"
I want to map this to my below SystemInformation
class properties. Based on Key need to set value in corresponding property.
public class SystemInformation
{
public string SystemId { get; set; }
public string SystemName { get; set; }
public string Location { get; set; }
}
Right now iam looping the IList<KeyValues
> object and setting the values in model comparing the key.
Is there any other way i can achieve this using Automapper or any other option since i have to do this similar operation for multiple models.