コード例 #1
0
 internal void Save()
 {
     if (_iniDocument != null)
     {
         _iniDocument.Save();
     }
 }
コード例 #2
0
        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();
                }
            }
        }