I have a sample class
public class sampleClass
{
public string givenName { get; set; }
public string familyName { get; set; }
}
and a set of values for that class contained in IDictionary<string, object> dataModel
. I can use reflection to iterate through the dataModel
and use the dataModel
key to get the value.
I would like to do something like:
void UpdateValues(IDictionary<string, object> dataModel)
{
Type sourceType = typeof(sampleClass);
foreach (PropertyInfo propInfo in (sourceType.GetProperties()))
{
if (dataModel.ContainsKey(propInfo.Name))
{
// set propInfo value here
propInfo.Value = dataModel[propInfo.Name];
}
}
}
But i have no idea how to do the line
propInfo.Value = dataModel[propInfo.Name];
Help! Thanks !!