System.Configuration.MgmtConfigurationRecord.RemoveConfigurationSectionGroup C# (CSharp) Method

RemoveConfigurationSectionGroup() private method

private RemoveConfigurationSectionGroup ( string group, string name ) : void
group string
name string
return void
        internal void RemoveConfigurationSectionGroup(string group, string name) {
            // Validate arguments
            VerifySectionName(name, null, false);

            string configKey = BaseConfigurationRecord.CombineConfigKey(group, name);

            // If it's not a registered section, there's nothing to do.
            if (FindFactoryRecord(configKey, true) == null) {
                return;
            }

            // Remove all descendent sections.
            ArrayList sections = GetDescendentSectionFactories(configKey);
            foreach (FactoryId descendent in sections) {
                RemoveConfigurationSection(descendent.Group, descendent.Name);
            }

            // Remove all descendent sections groups, including the configKey group.
            ArrayList sectionGroups = GetDescendentSectionGroupFactories(configKey);
            foreach (FactoryId descendent in sectionGroups) {
                //
                // If it's already removed, don't try to remove it again.
                // We don't do this test above the loop for configKey, because
                // the section groups contained within the section group may
                // be changed by the user once added.
                //
                if (RemovedSectionGroups.Contains(descendent.ConfigKey)) {
                    continue;
                }

                // If the section group has been evaluated, detatch it.
                ConfigurationSectionGroup sectionGroup = LookupSectionGroup(descendent.ConfigKey);
                if (sectionGroup != null) {
                    sectionGroup.DetachFromConfigurationRecord();
                }

                // Remove from list of all section group factories if this is the root declaration.
                bool isRootDeclaration = IsRootDeclaration(descendent.ConfigKey, false);
                if (_sectionGroupFactories != null && isRootDeclaration) {
                    _sectionGroupFactories.Remove(descendent.ConfigKey);
                }

                // Remove from list of factory records.
                if (!IsLocationConfig && _factoryRecords != null) {
                    _factoryRecords.Remove(descendent.ConfigKey);
                }

                // Remove from evaluated section groups.
                if (_sectionGroups != null) {
                    _sectionGroups.Remove(descendent.ConfigKey);
                }

                //
                // Add to list of section groups that are removed
                // Note that this will add section groups that might not be used
                // in this config file. That just results in some extra work during
                // save, it is not harmful.
                //
                RemovedSectionGroups.Add(descendent.ConfigKey, descendent.ConfigKey);
            }
        }