Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get current option values. Options validity is checked here. Returns only options which were present in file or options that were passed through SetOption.
        /// </summary>
        /// <param name="structure"></param>
        /// <returns></returns>
        internal IEnumerable <OptionValue> GetOptionValues(StructureInfo structure)
        {
            if (_mode == ParsingMode.Strict)
            {
                markInternalAsUnseen();
            }

            // crawl all sections
            foreach (var section in structure.Sections)
            {
                // acquire default comment if non-default one is not set (and is present in file)
                // also marks section as seen
                // in case of missing optional section, itforces its existende
                bool forced = checkForceSectionCommentAndSeen(section, knownSections);

                // Forced section, it is optional and not present
                if (forced)
                {
                    // crawl all options
                    foreach (var option in section.Options)
                    {
                        // skip optional options
                        if (option.IsOptional)
                        {
                            continue;
                        }

                        // return non-optional option
                        var optionValue = new OptionValue(option.Name, option.DefaultValue);
                        checkValidity(option, optionValue);
                        yield return(optionValue);
                    }
                }
                // Standard appropach of data extreaction
                else
                {
                    // crawl all options
                    foreach (var option in section.Options)
                    {
                        // acquire default comment if non-default is not set (and is present in file)
                        // also marks option as seen
                        checkOptionCommentAndSeen(option, knownSections);

                        // return value
                        object value       = extractValue(option, knownSections);
                        var    optionValue = new OptionValue(option.Name, value);
                        checkValidity(option, optionValue);
                        yield return(optionValue);
                    }
                }
            }

            if (_mode == ParsingMode.Strict)
            {
                checkInternalAsSeen();
            }
        }