/// <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); }
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()); } }
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()); } }