Exemplo n.º 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);
        }
Exemplo n.º 2
0
 public void TestInvalidUnit()
 {
     using (var reader = new StringReader("invalid"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 Assert.Throws <InvalidUnitException>(() => doc.GetDefaultSection());
             }
 }
Exemplo n.º 3
0
 public void TestDontParseDefaultSection()
 {
     using (var reader = new StringReader($"[{Section.DefaultSectionName}]"))
         using (var parser = new Parser.Parser(reader, IniOptions.Default))
             using (var doc = new ParsedSectionCollection(parser, IniOptions.Default))
             {
                 Assert.Throws <InvalidTokenException>(() => doc.GetDefaultSection());
             }
 }