I want to convert\map an existing object to IEnumerable<KeyValuePair<String, String>>
where the key the name of the given property is and the value the value of the given property.
I found this, but this does not quite fit into my scenario: automapper
I did this:
List<KeyValuePair<String, Object>> list = new List<KeyValuePair<String, Object>>();
foreach (var prop in genericType.GetType().GetProperties())
{
list.Add(new KeyValuePair<String, Object>(prop.Name, prop.GetValue(genericType, null)));
}
Is there a way without using reflection,if so how ?(genericType
is a Type I know of)