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

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

private BaseAdd ( ConfigurationElement element, bool throwIfExists, bool ignoreLocks ) : void
element ConfigurationElement
throwIfExists bool
ignoreLocks bool
Результат void
        private void BaseAdd(ConfigurationElement element, bool throwIfExists, bool ignoreLocks) {
            bool flagAsReplaced = false;
            bool localAddToEnd = internalAddToEnd;

            if (IsReadOnly()) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only));
            }

            if (LockItem == true && ignoreLocks == false) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_element_locked, _addElement));
            }

            Object key = GetElementKeyInternal(element);
            int iFoundItem = -1;
            for (int index = 0; index < _items.Count; index++) {
                Entry entry = (Entry)_items[index];
                if (CompareKeys(key, entry.GetKey(this))) {
                    if (entry._value != null && entry._value.LockItem == true && ignoreLocks == false) {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_collection_item_locked));
                    }
                    if (entry._entryType != EntryType.Removed && throwIfExists) {
                        if (!element.Equals(entry._value)) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_collection_entry_already_exists, key),
                                element.PropertyFileName(""), element.PropertyLineNumber(""));
                        }
                        else {
                            entry._value = element;
                        }
                        return;
                    }
                    if (entry._entryType != EntryType.Added) {
                        if ((CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap ||
                             CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate) &&
                            entry._entryType == EntryType.Removed &&
                            _removedItemCount > 0) {
                            _removedItemCount--; // account for the value
                        }
                        entry._entryType = EntryType.Replaced;
                        flagAsReplaced = true;
                    }
                    if (localAddToEnd || 
                        CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate) {
                        iFoundItem = index;
                        if (entry._entryType == EntryType.Added) {
                            localAddToEnd = true;
                        }
                        break;
                    }
                    else {
                        // check to see if the element is trying to set a locked property.
                        if (ignoreLocks == false) {
                            element.HandleLockedAttributes(entry._value);
                            // copy the lock from the removed element before setting the new element
                            element.MergeLocks(entry._value);
                        }
                        entry._value = element;
                        bModified = true;
                        return;
                    }
                }
            }

            // Brand new item.
            if (iFoundItem >= 0) {
                _items.RemoveAt(iFoundItem);

                // if the item being removed was inherited adjust the cout
                if (CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate &&
                    iFoundItem > Count + _removedItemCount - _inheritedCount) {
                    _inheritedCount--;
                }
            }
            BaseAddInternal(localAddToEnd ? -1 : iFoundItem, element, flagAsReplaced, ignoreLocks);
            bModified = true;
        }

Same methods

ConfigurationElementCollection::BaseAdd ( ConfigurationElement element ) : void
ConfigurationElementCollection::BaseAdd ( ConfigurationElement element, bool throwIfExists ) : void
ConfigurationElementCollection::BaseAdd ( int index, ConfigurationElement element ) : void
ConfigurationElementCollection::BaseAdd ( int index, ConfigurationElement element, bool ignoreLocks ) : void