System.Configuration.ConfigurationElementCollection.BaseAddInternal C# (CSharp) Метод

BaseAddInternal() приватный Метод

private BaseAddInternal ( int index, ConfigurationElement element, bool flagAsReplaced, bool ignoreLocks ) : void
index int
element ConfigurationElement
flagAsReplaced bool
ignoreLocks bool
Результат void
        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;
        }