GetKeys() public method

public GetKeys ( ) : string[]
return string[]
示例#1
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);
        }
示例#2
0
        public void GetAllKeys()
        {
            StringWriter writer = new StringWriter();

            writer.WriteLine("[Nini]");
            writer.WriteLine(" ; a comment");
            writer.WriteLine(" my key = something");
            writer.WriteLine(" dog = rover");
            writer.WriteLine(" cat = muffy");
            IniDocument doc = new IniDocument(new StringReader(writer.ToString()));

            IniSection section = doc.Sections["Nini"];

            Assert.AreEqual(4, section.ItemCount);
            Assert.AreEqual(3, section.GetKeys().Length);
            Assert.AreEqual("my key", section.GetKeys()[0]);
            Assert.AreEqual("dog", section.GetKeys()[1]);
            Assert.AreEqual("cat", section.GetKeys()[2]);
        }
示例#3
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);
        }