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 && xml == data) {
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;
}