Use reflection. In pseudo code:
Settings mySettingsClass = new Settings(); foreach (KeyValuePair<string, object> kvp in mySettings) { PropertyInfo pi = mySettingsClass.GetType().GetProperty(kvp.key, BindingFlags.Public | BindingFlags.Instance); if (pi != null) { pi.SetValue(mySettingsClass, kvp.Value, null); } }
Of course, if you read it back from the dataReader, you can use a slightly different approach and avoid using reflection (since the structure of the DataReader and the structure of the target object are known). Using reflection in this case is slower, but it is a good way to display data from one element to another in general - basically you take the source property, see if the target property exists on the target, and then assigns a value, if any.
slugster
source share