コード例 #1
0
        /// <summary>
        /// Get the comment, if any, for a given property
        /// </summary>
        /// <param name="identifier">Property identifier of form section.property. If no section is given, default section is assumed</param>
        /// <returns></returns>
        public string GetComment(string identifier)
        {
            var(sectionId, propertyId) = ParseCommentableIdentifier(identifier);

            // test default section first
            // NOTE: we pass sectionId because it actually functions as the property ID in the default section
            if (sections.GetDefaultSection().HasProperty(sectionId))
            {
                return(sections.GetDefaultSection().GetProperty(sectionId).Comment);
            }

            var section = sections.GetSection(sectionId);

            return(propertyId != null?section.GetProperty(propertyId).Comment : section.Comment);
        }
コード例 #2
0
 public void TestGetNonexistentSection()
 {
     using (var reader = new StringReader("[section]"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 Assert.Throws <ArgumentException>(() => doc.GetSection("nonexistent"));
             }
 }
コード例 #3
0
        public void GetSectionCaseInsensitiveParsing()
        {
            var options = new IniOptions(caseSensitive: false);

            using (var reader = new StringReader("[SECTION]"))
                using (var parser = new Parser.Parser(reader, options))
                    using (var doc = new ParsedSectionCollection(parser, options))
                    {
                        Assert.NotNull(doc.GetSection("section"));
                    }
        }
コード例 #4
0
        public void GetSectionCaseSensitiveParsing()
        {
            var options = new IniOptions(caseSensitive: true);

            using (var reader = new StringReader("[SECTION]"))
                using (var parser = new Parser.Parser(reader, options))
                    using (var doc = new ParsedSectionCollection(parser, options))
                    {
                        Assert.Throws <ArgumentException>(() => doc.GetSection("section"));
                    }
        }
コード例 #5
0
 public void TestGetSection()
 {
     using (var reader = new StringReader("[section1]\n[section2]\n[section3]"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 for (var i = 0; i < 3; i++)
                 {
                     var name    = $"section{i + 1}";
                     var section = doc.GetSection(name);
                     Assert.AreEqual(name, section.Name);
                 }
             }
 }
コード例 #6
0
 public void TestGetSectionsWithProperties()
 {
     using (var reader = new StringReader("[section1]\nvalue=10\n[section2]\nvalue=10\n[section3]\nvalue=10"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 for (var i = 0; i < 3; i++)
                 {
                     var name    = $"section{i + 1}";
                     var section = doc.GetSection(name);
                     Assert.AreEqual(name, section.Name);
                     Assert.AreEqual(1, section.GetProperties().Count());
                     Assert.AreEqual(true, section.HasProperty("value"));
                     Assert.AreEqual(10L, section.GetProperty("value").GetValueAs <long>());
                 }
             }
 }