<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0-preview.7.23375.6" />

RuntimeConfigurationRecord

using System.Configuration.Internal; using System.Reflection; using System.Xml; namespace System.Configuration { internal sealed class RuntimeConfigurationRecord : BaseConfigurationRecord { private sealed class RuntimeConfigurationFactory { private ConstructorInfo _sectionCtor; private IConfigurationSectionHandler _sectionHandler; internal RuntimeConfigurationFactory(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) { Init(configRecord, factoryRecord); } private void Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) { Type type = TypeUtil.GetType(configRecord.Host, factoryRecord.FactoryTypeName, true); if (typeof(ConfigurationSection).IsAssignableFrom(type)) _sectionCtor = TypeUtil.GetConstructor(type, typeof(ConfigurationSection), true); else { TypeUtil.VerifyAssignableType(typeof(IConfigurationSectionHandler), type, true); _sectionHandler = (IConfigurationSectionHandler)TypeUtil.CreateInstance(type); } } private static void CheckForLockAttributes(string sectionName, XmlNode xmlNode) { XmlAttributeCollection attributes = xmlNode.Attributes; if (attributes != null) { foreach (XmlAttribute item in attributes) { if (ConfigurationElement.IsLockAttributeName(item.Name)) throw new ConfigurationErrorsException(System.SR.Format(System.SR.Config_element_locking_not_supported, sectionName), item); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { if (xmlNode.NodeType == XmlNodeType.Element) CheckForLockAttributes(sectionName, childNode); } } internal object CreateSection(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) { if (!(_sectionCtor != (ConstructorInfo)null)) { if (reader == null) return null; XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader); CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode); object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath); return _sectionHandler.Create(parentConfig, configContext, xmlNode); } ConfigurationSection configurationSection = (ConfigurationSection)_sectionCtor.Invoke(null); configurationSection.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord); configurationSection.CallInit(); ConfigurationSection parentElement = (ConfigurationSection)parentConfig; configurationSection.Reset(parentElement); if (reader != null) configurationSection.DeserializeSection(reader); ConfigurationErrorsException errors = configurationSection.GetErrors(); if (errors != null) throw errors; configurationSection.SetReadOnly(); configurationSection.ResetModified(); return configurationSection; } } private static readonly SimpleBitVector32 s_runtimeClassFlags = new SimpleBitVector32(47); protected override SimpleBitVector32 ClassFlags => s_runtimeClassFlags; private RuntimeConfigurationRecord() { } internal static IInternalConfigRecord Create(InternalConfigRoot configRoot, IInternalConfigRecord parent, string configPath) { RuntimeConfigurationRecord runtimeConfigurationRecord = new RuntimeConfigurationRecord(); runtimeConfigurationRecord.Init(configRoot, (BaseConfigurationRecord)parent, configPath, null); return runtimeConfigurationRecord; } protected override object CreateSectionFactory(FactoryRecord factoryRecord) { return new RuntimeConfigurationFactory(this, factoryRecord); } protected override object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) { RuntimeConfigurationFactory runtimeConfigurationFactory = (RuntimeConfigurationFactory)factoryRecord.Factory; return runtimeConfigurationFactory.CreateSection(this, factoryRecord, sectionRecord, parentConfig, reader); } protected override object UseParentResult(string configKey, object parentResult, SectionRecord sectionRecord) { return parentResult; } protected override object GetRuntimeObject(object result) { ConfigurationSection configurationSection = result as ConfigurationSection; if (configurationSection != null) try { return configurationSection.GetRuntimeObject(); } catch (Exception inner) { throw new ConfigurationErrorsException(System.SR.Format(System.SR.Config_exception_in_config_section_handler, configurationSection.SectionInformation.SectionName), inner); } return result; } } }