Set property value using property name [duplicate]

You can try something like this

List<KeyValuePair<string, object>> _lObjects = GetObjectsList(); 
var class1 = new Class1();
var class1Type = typeof(class1); 
foreach(KeyValuePair<string, object> _pair in _lObjects)
  {   
       //class have this static property name stored in _pair.Key     
       class1Type.GetProperty(_pair.Key).SetValue(class1, _pair.Value); 
  } 

Leave a Comment