示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationSettingsReader"/> class.
        /// </summary>
        /// <param name="sectionName">Name of the configuration section.</param>
        /// <param name="configurationFile">The configuration file.</param>
        public ConfigurationSettingsReader(string sectionName, string configurationFile)
        {
            if (sectionName == null)
            {
                throw new ArgumentNullException("sectionName");
            }
            if (configurationFile == null)
            {
                throw new ArgumentNullException("configurationFile");
            }

            if (!Path.IsPathRooted(configurationFile))
            {
                configurationFile = Path.Combine(_configurationDirectory, configurationFile);
            }

            ExeConfigurationFileMap map = new ExeConfigurationFileMap();

            map.ExeConfigFilename = configurationFile;

            var configuration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

            _sectionHandler = (SectionHandler)configuration.GetSection(sectionName);

            if (_sectionHandler == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          ConfigurationSettingsReaderResources.SectionNotFound, sectionName));
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationSettingsReader"/> class.
        /// </summary>
        /// <param name="sectionName">Name of the configuration section.</param>
        public ConfigurationSettingsReader(string sectionName)
        {
            if (sectionName == null)
            {
                throw new ArgumentNullException("sectionName");
            }

            _sectionHandler = (SectionHandler)ConfigurationManager.GetSection(sectionName);

            if (_sectionHandler == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          ConfigurationSettingsReaderResources.SectionNotFound, sectionName));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationSettingsReader"/> class.
        /// </summary>
        /// <param name="sectionName">Name of the configuration section.</param>
        public ConfigurationSettingsReader(string sectionName)
        {
            if (sectionName == null)
            {
                throw new ArgumentNullException("sectionName");
            }

            _sectionHandler = (SectionHandler)ConfigurationManager.GetSection(sectionName);

            if (_sectionHandler == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          "The configuration section '{0}' could not be read.", sectionName));
            }
        }