/// <summary> /// Creates a new configuration sources based on the configuration information from the application's default /// configuration file. /// </summary> /// <param name="name">The name for the desired configuration source.</param> /// <returns>The new configuration source instance described in the configuration file.</returns> /// <exception cref="ConfigurationErrorsException">when no configuration information is found for name <paramref name="name"/>.</exception> /// <exception cref="ArgumentNullException">when <paramref name="name"/> is null or empty.</exception> public static IConfigurationSource Create(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } ConfigurationSourceSection configurationSourceSection = ConfigurationSourceSection.GetConfigurationSourceSection(); if (configurationSourceSection == null) { throw new ConfigurationErrorsException(Resources.ExceptionConfigurationSourceSectionNotFound); } ConfigurationSourceElement objectConfiguration = configurationSourceSection.Sources.Get(name); if (objectConfiguration == null) { throw new ConfigurationErrorsException( string.Format( CultureInfo.CurrentCulture, Resources.ExceptionNamedConfigurationNotFound, name, "ConfigurationSourceFactory")); } IConfigurationSource source = objectConfiguration.CreateSource(); return(source); }
private void CreateConfigurationSourceElement(ConfigurationSourceSectionNode node, ConfigurationSourceElement configurationSourceElement) { ConfigurationNode sourceNode = NodeCreationService.CreateNodeByDataType(configurationSourceElement.GetType(), new object[] { configurationSourceElement }); if (null == sourceNode) { LogNodeMapError(node, configurationSourceElement.GetType()); return; } if (configurationSourceSection.SelectedSource == configurationSourceElement.Name) defaultNode = (ConfigurationSourceElementNode)sourceNode; node.AddNode(sourceNode); }