// // Add a new configuration section group to this config file. // // Called from ConfigurationSectionGroupCollection.Add(). // Note this method DOES NOT update the associated ConfigurationSectionGroupCollection. // 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); }
internal void AddConfigurationSectionGroup(string group, string name, ConfigurationSectionGroup configSectionGroup) { if (base.IsLocationConfig) { throw new InvalidOperationException(System.Configuration.SR.GetString("Config_add_configurationsectiongroup_in_location_config")); } BaseConfigurationRecord.VerifySectionName(name, null, false); if (configSectionGroup == null) { throw ExceptionUtil.ParameterInvalid("name"); } if (configSectionGroup.Attached) { throw new InvalidOperationException(System.Configuration.SR.GetString("Config_add_configurationsectiongroup_already_added")); } string configKey = BaseConfigurationRecord.CombineConfigKey(group, name); if (base.FindFactoryRecord(configKey, true) != null) { throw new ArgumentException(System.Configuration.SR.GetString("Config_add_configurationsectiongroup_already_exists")); } if (this._sectionGroupFactories != null) { this._sectionGroupFactories.Add(configKey, new FactoryId(configKey, group, name)); } string type = configSectionGroup.Type; if (type == null) { type = base.Host.GetConfigTypeName(configSectionGroup.GetType()); } FactoryRecord factoryRecord = new FactoryRecord(configKey, group, name, type, base.ConfigStreamInfo.StreamName, -1); base.EnsureFactories()[configKey] = factoryRecord; this.SectionGroups[configKey] = configSectionGroup; if (this._removedSectionGroups != null) { this._removedSectionGroups.Remove(configKey); } configSectionGroup.AttachToConfigurationRecord(this, factoryRecord); }