/// <summary> /// Event fired on load. /// </summary> /// <param name="config">Config to load.</param> public virtual void OnLoad(object config) { Execute(() => { Type settings = config.GetType(); _configStore.Load(); foreach (var prop in settings.GetProperties()) { if (!ExcludedProps.ContainsKey(prop.Name)) { // 1. Get value. object val = _configStore["", prop.Name]; // 2. Set the value. Reflection.ReflectionUtils.SetProperty(config, prop.Name, val); } } }); }
/// <summary> /// Event fired on save. /// </summary> /// <param name="config">Config to use.</param> public virtual void OnSave(object config) { Execute(() => { Type settings = config.GetType(); foreach (var prop in settings.GetProperties()) { if (!ExcludedProps.ContainsKey(prop.Name)) { // 1. Get value. object val = prop.GetValue(config, null); // 2. Convert to string checking for min values. e.g. DateTime.Min, // string valStr = Types.TypeParsers.ConvertTo<string>(val); _configStore["", prop.Name] = val; } } _configStore.Save(); }); }