Beispiel #1
0
        /// <summary>
        /// Checks whether given section exists and has appropriate comment,
        /// if it has no comment, it claims the default one
        ///
        /// Forces section existence
        ///
        /// In case the section does not exist, it is created with appropriate default comment,
        /// this is the case of optional sections not presented in configuration file,
        /// these should not be stored into outStream (unles filled)
        /// Also in getValues its nonOptional members are provided from within structure info,
        /// as they are not in InnerRepresentation
        /// </summary>
        /// <param name="section">Fully typed section info, with appropriate comment set</param>
        /// <param name="knownSections">Dictionary of all known sections</param>
        /// <returns>Whether section had to be forced, thus created anew (not present in source file)</returns>
        private static bool checkForceSectionCommentAndSeen(SectionInfo section, Dictionary <QualifiedSectionName, InnerSection> knownSections)
        {
            var qSec = section.Name;

            // only if exists
            if (knownSections.ContainsKey(qSec))
            {
                var innerSect = knownSections[qSec];

                // mark as seen for strict mode
                innerSect.Seen = true;

                // only if it has no comment, default one is claimed
                if (innerSect.Comment == null)
                {
                    innerSect.Comment = section.DefaultComment;
                }

                return(false);
            }
            // Force existence for optional
            else if (section.IsOptional)
            {
                var newSection = new InnerSection(section.Name, section.DefaultComment);
                newSection.Seen = true;
                knownSections.Add(section.Name, newSection);
                return(true);
            }
            // Exception will be thrown later, with more info
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Register structure info (used when file is not being read)
        /// </summary>
        /// <param name="structure">Structure info</param>
        internal void RegisterStructure(StructureInfo structure)
        {
            // crawl all sections
            foreach (var section in structure.Sections)
            {
                // Create section and extract comment
                var newSection = new InnerSection(section.Name, section.DefaultComment);
                knownSections.Add(section.Name, newSection);

                // crawl all options
                foreach (var option in section.Options)
                {
                    // Skip optional options
                    if (option.IsOptional)
                    {
                        continue;
                    }

                    // Create option and extract comment
                    var newOption = new InnerOption(option.Name, null);
                    newOption.Comment = option.DefaultComment;
                    newSection.Options.Add(option.Name, newOption);
                }
            }
        }