private void BaseAddInternal(int index, ConfigurationElement element, bool flagAsReplaced, bool ignoreLocks) { element.AssociateContext(base._configRecord); if (element != null) { element.CallInit(); } if (this.IsReadOnly()) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_read_only")); } if (!ignoreLocks) { if ((this.CollectionType == ConfigurationElementCollectionType.BasicMap) || (this.CollectionType == ConfigurationElementCollectionType.BasicMapAlternate)) { if (BaseConfigurationRecord.IsReservedAttributeName(this.ElementName)) { throw new ArgumentException(System.Configuration.SR.GetString("Basicmap_item_name_reserved", new object[] { this.ElementName })); } base.CheckLockedElement(this.ElementName, null); } if ((this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap) || (this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate)) { base.CheckLockedElement(this._addElement, null); } } if ((this.CollectionType == ConfigurationElementCollectionType.BasicMapAlternate) || (this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate)) { if (index == -1) { index = (this.Count + this._removedItemCount) - this._inheritedCount; } else if ((index > ((this.Count + this._removedItemCount) - this._inheritedCount)) && !flagAsReplaced) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_cannot_add_items_below_inherited_items")); } } if (((this.CollectionType == ConfigurationElementCollectionType.BasicMap) && (index >= 0)) && (index < this._inheritedCount)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_cannot_add_items_above_inherited_items")); } EntryType type = !flagAsReplaced ? EntryType.Added : EntryType.Replaced; object elementKeyInternal = this.GetElementKeyInternal(element); if (index >= 0) { if (index > this._items.Count) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("IndexOutOfRange", new object[] { index })); } this._items.Insert(index, new Entry(type, elementKeyInternal, element)); } else { this._items.Add(new Entry(type, elementKeyInternal, element)); } this.bModified = true; }
private void BaseAddInternal(int index, ConfigurationElement element, bool flagAsReplaced, bool ignoreLocks) { // Allow the element to initialize itself after its // constructor has been run so that it may access // virtual methods. element.AssociateContext(_configRecord); if (element != null) { element.CallInit(); } if (IsReadOnly()) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only)); } if (!ignoreLocks) { // during reset we ignore locks so we can copy the elements if (CollectionType == ConfigurationElementCollectionType.BasicMap || CollectionType == ConfigurationElementCollectionType.BasicMapAlternate) { if (BaseConfigurationRecord.IsReservedAttributeName(ElementName)) { throw new ArgumentException(SR.GetString(SR.Basicmap_item_name_reserved, ElementName)); } CheckLockedElement(ElementName, null); } if (CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap || CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate) { CheckLockedElement(_addElement, null); } } if (CollectionType == ConfigurationElementCollectionType.BasicMapAlternate || CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate) { if (index == -1) { index = Count + _removedItemCount - _inheritedCount; // insert before inherited, but after any removed } else { if (index > Count + _removedItemCount - _inheritedCount && flagAsReplaced == false) { throw (new ConfigurationErrorsException(SR.GetString(SR.Config_base_cannot_add_items_below_inherited_items))); } } } if (CollectionType == ConfigurationElementCollectionType.BasicMap && index >= 0 && index < _inheritedCount) { throw (new ConfigurationErrorsException(SR.GetString(SR.Config_base_cannot_add_items_above_inherited_items))); } EntryType entryType = (flagAsReplaced == false) ? EntryType.Added : EntryType.Replaced; Object key = GetElementKeyInternal(element); if (index >= 0) { if (index > _items.Count) { throw new ConfigurationErrorsException(SR.GetString(SR.IndexOutOfRange, index)); } _items.Insert(index, new Entry(entryType, key, element)); } else { _items.Add(new Entry(entryType, key, element)); } bModified = true; }