internal ConfigurationElement GetElementAtParentLocationInFileContext(FileContext core)
{
if (Section == null)
{
return null;
}
if (Section.Location == null)
{
if (core != null && core.Parent == null && Schema.Path == "configProtectedData/providers")
{
// IMPORTANT: to load providers from machine.config.
return core.GetSection(Section.SectionPath).GetChildElement("providers");
}
return null;
}
string parentLocation = Section.Location.GetParentPath();
while (true)
{
var parentSection = core.GetSection(Section.SectionPath, parentLocation);
// IMPORTANT: allow null section as web.config does not have the sections.
var parentElement = parentSection?.GetElementByPath(Schema.Path);
if (parentElement != null)
{
return parentElement;
}
if (parentLocation == null)
{
return null;
}
parentLocation = parentLocation.GetParentPath();
}
}