ConfigFile.Write C# (CSharp) Method

Write() public method

public Write ( Stream stream ) : bool
stream Stream
return bool
    public bool Write(Stream stream)
    {
        try
        {
            StreamWriter sw = new StreamWriter(stream);
            foreach (KeyValuePair<string, Dictionary<string, string>> temp in m_SectiontList)
            {
                sw.WriteLine("[{0}]", temp.Key);
                foreach (KeyValuePair<string, string> kvp in m_SectiontList[temp.Key])
                {
                    sw.WriteLine("{0} = {1}", kvp.Key, kvp.Value);
                }
            }
            sw.Close();
            return true;
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
            return false;
        }
    }

Same methods

ConfigFile::Write ( string path ) : bool

Usage Example

        public void WriteMultipleTest()
        {
            Delete();
            var configFile = new ConfigFile <Configuration>(FilePath);
            var one        = new TestConfigSection()
            {
                Value = 1
            };
            var two = new AnotherConfigSection()
            {
                Number = 2
            };

            configFile.Write(one, two);

            Assert.AreEqual(1, configFile.Read <TestConfigSection>().Value);
            Assert.AreEqual(2, configFile.Read <AnotherConfigSection>().Number);

            Delete();
            var three = new AThirdSection()
            {
                Int = 3
            };

            configFile.Write(one, two, three);

            Assert.AreEqual(1, configFile.Read <TestConfigSection>().Value);
            Assert.AreEqual(2, configFile.Read <AnotherConfigSection>().Number);
            Assert.AreEqual(3, configFile.Read <AThirdSection>().Int);
        }
All Usage Examples Of ConfigFile::Write