internal object GetData() { if (!IniFilePath.IsNullOrWhiteSpace() && File.Exists(IniFilePath)) { using (ChoIniDocument iniDocument = ChoIniDocument.Load(IniFilePath)) { ChoIniSectionNode iniSectionNode = iniDocument.GetSection(IniSectionName); if (iniSectionNode != null) { return(iniSectionNode.ToNameValueCollection()); } } } return(null); }
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 GetSection(string sectionName) { return(_iniDocument.GetSection(sectionName)); }