Exemplo n.º 1
0
        /// <summary>
        /// Pops a section that was previously push into the current configuration.
        /// </summary>
        /// <param name="name">The name of the section to restore.</param>
        /// <returns>An instance of the <see cref="GeneralConfigurator"/>.</returns>
        public GeneralConfigurator PopSection(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (_sections.ContainsKey(name))
            {
                ConfigurationSection section = _configuration.GetSection(name);
                if (section != null)
                {
                    _configuration.Sections.Remove(name);
                }

                ConfigurationSectionInfo info = _sections[name];
                section = new DefaultSection();
                section.SectionInformation.SetRawXml(info.Xml);
                section.SectionInformation.Type = info.Type;
                _configuration.Sections.Add(name, section);
                MarkDirty();
            }

            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Pushes the section on a persisted section stack.
        /// </summary>
        /// <param name="name">The name of the section to save.</param>
        /// <returns>An instance of the <see cref="GeneralConfigurator"/>.</returns>
        /// <remarks>If a section is pushed multiple times only the last instance is persisted.</remarks>
        public GeneralConfigurator PushSection(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            DefaultSection section = _configuration.Sections[name] as DefaultSection;

            if (section != null)
            {
                _sections[name] = new ConfigurationSectionInfo(section);
            }

            return(this);
        }