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

BaseClear() защищенный Метод

protected BaseClear ( ) : void
Результат void
        protected internal void BaseClear() {
            if (IsReadOnly()) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only));
            }

            CheckLockedElement(_clearElement, null);  // has clear been locked?
            CheckLockedElement(_removeElement, null); // has remove been locked? Clear implies remove

            bModified = true;
            bCollectionCleared = true;
            if ((CollectionType == ConfigurationElementCollectionType.BasicMap ||
                 CollectionType == ConfigurationElementCollectionType.BasicMapAlternate)
                && _inheritedCount > 0) {
                int RemoveIndex = 0;
                if (CollectionType == ConfigurationElementCollectionType.BasicMapAlternate) {
                    RemoveIndex = 0; // Inherited items are at the bottom and cannot be removed
                }
                if (CollectionType == ConfigurationElementCollectionType.BasicMap) {
                    RemoveIndex = _inheritedCount; // inherited items are at the top and cannot be removed
                }
                while (Count - _inheritedCount > 0) {
                    _items.RemoveAt(RemoveIndex);
                }
            }
            else {
                // do not clear any locked items
                // _items.Clear();
                int inheritedRemoved = 0;
                int removedRemoved = 0;
                int initialCount = Count;
                
                // check for locks before removing any items from the collection
                for (int CheckIndex = 0; CheckIndex < _items.Count; CheckIndex++) {
                    Entry entry = (Entry)_items[CheckIndex];
                    if (entry._value != null && entry._value.LockItem == true) {
                        throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_collection_item_locked_cannot_clear));
                    }
                }

                for (int RemoveIndex = _items.Count - 1; RemoveIndex >= 0; RemoveIndex--) {
                    Entry entry = (Entry)_items[RemoveIndex];
                    if ((CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap &&
                            RemoveIndex < _inheritedCount) ||
                        (CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate &&
                            (RemoveIndex >= initialCount - _inheritedCount))) {
                        inheritedRemoved++;
                    }
                    if (entry._entryType == EntryType.Removed) {
                        removedRemoved++;
                    }

                    _items.RemoveAt(RemoveIndex);
                }
                _inheritedCount -= inheritedRemoved;
                _removedItemCount -= removedRemoved;
            }
        }