private void SetOrUpdateKeyValue(SettingsPropertyValue property, KeyUpdateMode mode) { var keyName = property.Name; var keyData = new KeyData(keyName) { Value = property.SerializedValue.ToString() }; var sectionName = GetSectionNameByPropertyName(property.Name); if (sectionName != null) { var section = _iniData.Sections.GetSectionData(sectionName); if (mode == KeyUpdateMode.SetKeyValue && !section.Keys.ContainsKey(property.Name)) { section.Keys.AddKey(keyName); } //Do not save empty values if (!string.IsNullOrEmpty(keyData.Value)) { section.Keys.SetKeyData(keyData); } else { section.Keys.RemoveKey(keyName); } } }
public void SetOrUpdateProvertyValues(IEnumerable properties, KeyUpdateMode mode) { var errorMessage = mode == KeyUpdateMode.SetKeyValue ? InformationResources.ERROR_APPLICATION_SETTINGS_SET_OR_SAVE : InformationResources.ERROR_APPLICATION_SETTINGS_UPDATE; foreach (var property in properties.Cast <SettingsPropertyValue>().Where(property => property.IsDirty)) { SetOrUpdateKeyValue(property, mode); } try { SaveIniFile(); } catch { throw new SettingsException(errorMessage); } }