internal ConfigurationSection FindImmediateParentSection(ConfigurationSection section) {
ConfigurationSection result = null;
string configKey = section.SectionInformation.SectionName;
SectionRecord sectionRecord = GetSectionRecord(configKey, false);
if (sectionRecord.HasLocationInputs) {
SectionInput input = sectionRecord.LastLocationInput;
Debug.Assert(input.HasResult, "input.HasResult");
result = (ConfigurationSection) input.Result;
}
else if (IsRootDeclaration(configKey, true)) {
FactoryRecord factoryRecord = GetFactoryRecord(configKey, false);
object resultObject;
object resultRuntimeObject;
CreateSectionDefault(configKey, false, factoryRecord, null, out resultObject, out resultRuntimeObject);
result = (ConfigurationSection) resultObject;
}
else {
MgmtConfigurationRecord current = this.MgmtParent;
while (!current.IsRootConfig) {
sectionRecord = current.GetSectionRecord(configKey, false);
if (sectionRecord != null && sectionRecord.HasResult) {
result = (ConfigurationSection) sectionRecord.Result;
break;
}
current = current.MgmtParent;
}
Debug.Assert(!current.IsRootConfig, "An immediate parent result should have been found");
}
if (!result.IsReadOnly()) {
result.SetReadOnly();
}
return result;
}