Set() public method

public Set ( ) : void
return void
示例#1
0
        public void SaveAsMysqlStyle()
        {
            string     filePath = "Save.ini";
            FileStream stream   = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();

            doc.FileType = IniFileType.MysqlStyle;
            IniSection section = new IniSection("Pets");

            section.Set("my comment");
            section.Set("dog", "rover");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            StringWriter writer = new StringWriter();

            writer.WriteLine("[Pets]");
            writer.WriteLine("# my comment");
            writer.WriteLine("dog = rover");

            StreamReader reader = new StreamReader(filePath);

            Assert.AreEqual(writer.ToString(), reader.ReadToEnd());
            reader.Close();

            IniDocument iniDoc = new IniDocument();

            iniDoc.FileType = IniFileType.MysqlStyle;
            iniDoc.Load(filePath);

            File.Delete(filePath);
        }
示例#2
0
        public void SaveToStream()
        {
            string     filePath = "SaveToStream.ini";
            FileStream stream   = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc     = new IniDocument();
            IniSection  section = new IniSection("Pets");

            section.Set("dog", "rover");
            section.Set("cat", "muffy");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            IniDocument newDoc = new IniDocument(new FileStream(filePath,
                                                                FileMode.Open));

            section = newDoc.Sections["Pets"];
            Assert.IsNotNull(section);
            Assert.AreEqual(2, section.GetKeys().Length);
            Assert.AreEqual("rover", section.GetValue("dog"));
            Assert.AreEqual("muffy", section.GetValue("cat"));

            stream.Close();

            File.Delete(filePath);
        }
示例#3
0
        public void SetKey() {
            IniDocument doc = new IniDocument();

            IniSection section = new IniSection("new section");
            doc.Sections.Add(section);

            section.Set("new key", "some value");

            Assert.IsTrue(section.Contains("new key"));
            Assert.AreEqual("some value", section.GetValue("new key"));
        }
示例#4
0
        /// <summary>
        /// Loads the file not saving comments.
        /// </summary>
        private void LoadReader(IniReader reader)
        {
            reader.IgnoreComments = false;
            var        sectionFound = false;
            IniSection section      = null;

            try {
                while (reader.Read())
                {
                    switch (reader.Type)
                    {
                    case IniType.Empty:
                        if (!sectionFound)
                        {
                            initialComment.Add(reader.Comment);
                        }
                        else
                        {
                            section.Set(reader.Comment);
                        }

                        break;

                    case IniType.Section:
                        sectionFound = true;
                        // If section already exists then overwrite it
                        if (sections[reader.Name] != null)
                        {
                            sections.Remove(reader.Name);
                        }
                        section = new IniSection(reader.Name, reader.Comment);
                        sections.Add(section);

                        break;

                    case IniType.Key:
                        if (section.GetValue(reader.Name) == null)
                        {
                            section.Set(reader.Name, reader.Value, reader.Comment);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex) {
                throw;
            }
            finally {
                // Always close the file
                reader.Close();
            }
        }
示例#5
0
        public void SetKey()
        {
            IniDocument doc = new IniDocument();

            IniSection section = new IniSection("new section");

            doc.Sections.Add(section);

            section.Set("new key", "some value");

            Assert.IsTrue(section.Contains("new key"));
            Assert.AreEqual("some value", section.GetValue("new key"));
        }
示例#6
0
        public void SambaLoadAsStandard()
        {
            string     filePath = "Save.ini";
            FileStream stream   = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();

            doc.FileType = IniFileType.SambaStyle;
            IniSection section = new IniSection("Pets");

            section.Set("my comment");
            section.Set("dog", "rover");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            IniDocument iniDoc = new IniDocument();

            iniDoc.FileType = IniFileType.Standard;
            iniDoc.Load(filePath);

            File.Delete(filePath);
        }
示例#7
0
        /// <summary>
        /// Loads the file not saving comments.
        /// </summary>
        private void LoadReader(IniReader reader) {
            reader.IgnoreComments = false;
            var sectionFound = false;
            IniSection section = null;

            try {
                while(reader.Read()) {
                    switch(reader.Type) {
                        case IniType.Empty:
                            if(!sectionFound) {
                                initialComment.Add(reader.Comment);
                            }
                            else {
                                section.Set(reader.Comment);
                            }

                            break;
                        case IniType.Section:
                            sectionFound = true;
                            // If section already exists then overwrite it
                            if(sections[reader.Name] != null) {
                                sections.Remove(reader.Name);
                            }
                            section = new IniSection(reader.Name, reader.Comment);
                            sections.Add(section);

                            break;
                        case IniType.Key:
                            if(section.GetValue(reader.Name) == null) {
                                section.Set(reader.Name, reader.Value, reader.Comment);
                            }
                            break;
                    }
                }
            }
            catch(Exception ex) {
                throw;
            }
            finally {
                // Always close the file
                reader.Close();
            }
        }
示例#8
0
        public void SambaLoadAsStandard() {
            string filePath = "Save.ini";
            FileStream stream = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();
            doc.FileType = IniFileType.SambaStyle;
            IniSection section = new IniSection("Pets");
            section.Set("my comment");
            section.Set("dog", "rover");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            IniDocument iniDoc = new IniDocument();
            iniDoc.FileType = IniFileType.Standard;
            iniDoc.Load(filePath);

            File.Delete(filePath);
        }
示例#9
0
        public void SaveAsMysqlStyle() {
            string filePath = "Save.ini";
            FileStream stream = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();
            doc.FileType = IniFileType.MysqlStyle;
            IniSection section = new IniSection("Pets");
            section.Set("my comment");
            section.Set("dog", "rover");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            StringWriter writer = new StringWriter();
            writer.WriteLine("[Pets]");
            writer.WriteLine("# my comment");
            writer.WriteLine("dog = rover");

            StreamReader reader = new StreamReader(filePath);
            Assert.AreEqual(writer.ToString(), reader.ReadToEnd());
            reader.Close();

            IniDocument iniDoc = new IniDocument();
            iniDoc.FileType = IniFileType.MysqlStyle;
            iniDoc.Load(filePath);

            File.Delete(filePath);
        }
示例#10
0
        public void SaveToStream() {
            string filePath = "SaveToStream.ini";
            FileStream stream = new FileStream(filePath, FileMode.Create);

            // Create a new document and save to stream
            IniDocument doc = new IniDocument();
            IniSection section = new IniSection("Pets");
            section.Set("dog", "rover");
            section.Set("cat", "muffy");
            doc.Sections.Add(section);
            doc.Save(stream);
            stream.Close();

            IniDocument newDoc = new IniDocument(new FileStream(filePath,
                                                                FileMode.Open));
            section = newDoc.Sections["Pets"];
            Assert.IsNotNull(section);
            Assert.AreEqual(2, section.GetKeys().Length);
            Assert.AreEqual("rover", section.GetValue("dog"));
            Assert.AreEqual("muffy", section.GetValue("cat"));

            stream.Close();

            File.Delete(filePath);
        }