public IniSectionCollection(IniDocument document) { if (document == null) { throw new ArgumentNullException("document"); } ownerDocument = document; this.sections = new List <IniSection>(); }
/// <summary> /// Writes out the whole document. /// </summary> /// <param name="iniDocument"></param> public void WriteDocument(IniDocument iniDocument) { if (iniDocument == null) { throw new ArgumentNullException("iniDocument"); } // Dokumentumhoz tartozó kommentek if (this.WriteComments && iniDocument.CommentLines.Count > 0) { this.WriteCommentLines(iniDocument.CommentLines); writer.WriteLine(); } // Szekciók kiírása foreach (IniSection s in this.Formatting.SortSections ? iniDocument.Sections.OrderBy(s => s.Header) : iniDocument.Sections as IEnumerable <IniSection> ) { this.WriteSection(s); } }
/// <summary> /// Reads the whole document. /// </summary> public void ReadDocument(IniDocument document) { if (document == null) { throw new ArgumentNullException("document"); } // Tartalom törlése if (this.ClearDocument) { document.Sections.Clear(); document.CommentLines.Clear(); } // Nullázás this.CurrentLineNumber = this.CurrentLinePosition = 0; this.CurrentLineText = String.Empty; IniSection currentSection = null; while (true) { // Újabb sor beolvasása this.CurrentLineText = reader.ReadLine(); // Megszakítás if (this.CurrentLineText == null) { break; } this.CurrentLineNumber++; this.CurrentLinePosition = 0; string trimmedLine = this.CurrentLineText.TrimStart(); // Üres sor if (trimmedLine.Length == 0) { continue; } // Szekció beolvasása if (trimmedLine.StartsWith("[")) { // Előző szekció hozzáadása a dokumentumhoz if (currentSection != null) { document.Sections.Add(currentSection); } this.CurrentLinePosition = this.CurrentLineText.IndexOf('[') + 1; // Új szekció hozzáadása currentSection = new IniSection(this.ReadSectionHeader()); // Hiányzó ] if (this.ReadChar() != ']') { throw new IniReadException("Missing ']'.", this.CurrentLineNumber, this.CurrentLinePosition); } } // Komment beolvasása else if (trimmedLine.StartsWith(";")) { this.CurrentLinePosition = this.CurrentLineText.IndexOf(';'); if (currentSection != null) { currentSection.CommentLines.Add(this.ReadComment()); } else { document.CommentLines.Add(this.ReadComment()); } } // Paraméter beolvasása else { // White space átugrása this.ReadWhiteSpace(); // Név string name = this.ReadParameterName(); if (name.Length == 0) { throw new IniReadException("Parameter name is missing.", this.CurrentLineNumber, this.CurrentLinePosition); } this.ReadWhiteSpace(); // Név/érték elválasztó if (this.ReadChar() != this.SyntaxDefinition.NameValueDelimiter) { throw new IniReadException("Parameter name can contain only alphabetical and numerical characters.", this.CurrentLineNumber, this.CurrentLinePosition); } this.ReadWhiteSpace(); // Érték string value = this.ReadParameterValue(); if (value.Length == 0) { throw new IniReadException("Parameter value is missing.", this.CurrentLineNumber, this.CurrentLinePosition); } this.ReadWhiteSpace(); // Komment string description = null; if (this.ReadChar() == this.SyntaxDefinition.CommentStartChar) { description = this.ReadComment(); } // Új paraméter hozzáadása currentSection.Parameters.Add( new IniParameter(name, value) { Description = description } ); } } if (currentSection != null) { document.Sections.Add(currentSection); } }