/ Published in: C#
Since your domain object is passed in as a ref parameter, it cannot be cast to object, you must box it prior to calling the method. The caller of the method must also ensure that the System.Type of the value parameter matches the type expected by the property being updated.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
object oExampleContainer = example; private void updateObjectProperty(ref object thisObject, string propertyName, object value, List<string> excludeList) { if (!excludeList.Contains(propertyName)) { if (thisObject != null) { Type thisType = thisObject.GetType(); PropertyInfo[] propertyInfos = thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo info in propertyInfos) { if (info.Name.ToUpper() == propertyName.ToUpper()) { info.SetValue(thisObject, value, null); break; } } } } }