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

AddConfigurationSectionGroup() private method

private AddConfigurationSectionGroup ( string group, string name, ConfigurationSectionGroup configSectionGroup ) : void
group string
name string
configSectionGroup ConfigurationSectionGroup
return void
        internal void AddConfigurationSectionGroup(string group, string name, ConfigurationSectionGroup configSectionGroup) {
            // <location> tags can't have a <configSections> declaration.
            if (IsLocationConfig) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsectiongroup_in_location_config));
            }

            // Validate name argument.
            VerifySectionName(name, null, false);

            // Validate configSectionGroup argument.
            if (configSectionGroup == null) {
                throw ExceptionUtil.ParameterInvalid("name");
            }

            // A section group can only belong to one section group collection.
            if (configSectionGroup.Attached) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsectiongroup_already_added));
            }

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

            // Do not add if the section group already exists, even if it is of a different type.
            FactoryRecord factoryRecord = FindFactoryRecord(configKey, true);
            if (factoryRecord != null) {
                throw new ArgumentException(SR.GetString(SR.Config_add_configurationsectiongroup_already_exists));
            }

            // Add to list of all section groups.
            if (_sectionGroupFactories != null) {
                _sectionGroupFactories.Add(configKey, new FactoryId(configKey, group, name));
            }

            // Get the type name - if it is not specified explicitly, get it from the type of the object.
            string typeName = configSectionGroup.Type;
            if (typeName == null) {
                typeName = Host.GetConfigTypeName(configSectionGroup.GetType());
            }

            // Create a factory record and add it to the collection of factory records.
            factoryRecord = new FactoryRecord(configKey, group, name, typeName, ConfigStreamInfo.StreamName, -1);
            EnsureFactories()[configKey] = factoryRecord;

            // Add it to list of evaluated configuration section groups.
            SectionGroups[configKey] = configSectionGroup;

            // Remove it from RemovedSectionGroups if it was previously removed.
            if (_removedSectionGroups != null) {
                _removedSectionGroups.Remove(configKey);
            }

            // Attach to the configuration record.
            configSectionGroup.AttachToConfigurationRecord(this, factoryRecord);
        }