internal ConfigurationSection GetSectionInstance(SectionInfo config, bool createDefaultInstance) { object data = _elementData[config]; var sec = data as ConfigurationSection; if (sec != null || !createDefaultInstance) { return(sec); } var secObj = config.CreateInstance(); sec = secObj as ConfigurationSection; if (sec == null) { var ds = new DefaultSection(); ds.SectionHandler = secObj as IConfigurationSectionHandler; sec = ds; } sec.Configuration = this; ConfigurationSection parentSection = null; if (Parent != null) { parentSection = Parent.GetSectionInstance(config, true); sec.SectionInformation.SetParentSection(parentSection); } sec.SectionInformation.ConfigFilePath = FilePath; sec.ConfigContext = _system.Host.CreateDeprecatedConfigContext(_configPath); var xml = data as string; sec.RawXml = xml; sec.Reset(parentSection); if (xml != null) { using (var r = XmlReader.Create(new StringReader(xml))) { sec.DeserializeSection(r); } if (!string.IsNullOrEmpty(sec.SectionInformation.ConfigSource) && !string.IsNullOrEmpty(FilePath)) { sec.DeserializeConfigSource(Path.GetDirectoryName(FilePath)); } } _elementData[config] = sec; return(sec); }
internal ConfigurationSection GetSectionInstance(SectionInfo config, bool createDefaultInstance) { object data = elementData [config]; ConfigurationSection sec = data as ConfigurationSection; if (sec != null || !createDefaultInstance) { return(sec); } object secObj = config.CreateInstance(); sec = secObj as ConfigurationSection; if (sec == null) { DefaultSection ds = new DefaultSection(); ds.SectionHandler = secObj as IConfigurationSectionHandler; sec = ds; } sec.Configuration = this; ConfigurationSection parentSection = null; if (parent != null) { parentSection = parent.GetSectionInstance(config, true); sec.SectionInformation.SetParentSection(parentSection); } sec.SectionInformation.ConfigFilePath = FilePath; sec.ConfigContext = system.Host.CreateDeprecatedConfigContext(configPath); string xml = data as string; sec.RawXml = xml; sec.Reset(parentSection); if (xml != null) { XmlTextReader r = new ConfigXmlTextReader(new StringReader(xml), FilePath); sec.DeserializeSection(r); r.Close(); if (!String.IsNullOrEmpty(sec.SectionInformation.ConfigSource) && !String.IsNullOrEmpty(FilePath)) { sec.DeserializeConfigSource(Path.GetDirectoryName(FilePath)); } } elementData [config] = sec; return(sec); }
internal ConfigurationSection GetSectionInstance (SectionInfo config, bool createDefaultInstance) { object data = elementData [config]; ConfigurationSection sec = data as ConfigurationSection; if (sec != null || !createDefaultInstance) return sec; object secObj = config.CreateInstance (); sec = secObj as ConfigurationSection; if (sec == null) { DefaultSection ds = new DefaultSection (); ds.SectionHandler = secObj as IConfigurationSectionHandler; sec = ds; } sec.Configuration = this; ConfigurationSection parentSection = null; if (parent != null) { parentSection = parent.GetSectionInstance (config, true); sec.SectionInformation.SetParentSection (parentSection); } sec.SectionInformation.ConfigFilePath = FilePath; sec.ConfigContext = system.Host.CreateDeprecatedConfigContext(configPath); string xml = data as string; sec.RawXml = xml; sec.Reset (parentSection); if (xml != null) { XmlTextReader r = new ConfigXmlTextReader (new StringReader (xml), FilePath); sec.DeserializeSection (r); r.Close (); if (!String.IsNullOrEmpty (sec.SectionInformation.ConfigSource) && !String.IsNullOrEmpty (FilePath)) sec.DeserializeConfigSource (Path.GetDirectoryName (FilePath)); } elementData [config] = sec; return sec; }