Friday, September 02, 2011

c# assign values to object property by property name

Class1 obj= new Class1();
string propertyName = "name1";
string objValue = "";
Type type = obj.GetType();
PropertyInfo prop = type.GetProperty(propertyName );
prop.SetValue(obj, objValue , null);

No comments: