internal void SaveData(object data) { if (!(data is NameValueCollection)) { throw new ChoConfigurationException("Data object is not NameValueCollection object."); } NameValueCollection nameValueCollection = data as NameValueCollection; if (!IniFilePath.IsNullOrWhiteSpace()) { if (!File.Exists(IniFilePath)) { using (File.CreateText(IniFilePath)) { } } using (ChoIniDocument iniDocument = new ChoIniDocument(IniFilePath)) { ChoIniSectionNode sectionNode = iniDocument.GetSection(IniSectionName); if (sectionNode == null) { sectionNode = iniDocument.AddSection(IniSectionName); } sectionNode.ClearNodes(); foreach (string key in nameValueCollection.AllKeys) { sectionNode.AddNameValueNode(key, nameValueCollection[key] == null ? String.Empty : nameValueCollection[key].ToString()); } sectionNode.AppendNewLine(); iniDocument.Save(); } } }
public ChoIniSectionNode AddSection(string sectionName) { return(_iniDocument.AddSection(sectionName)); }