Equals() public method

public Equals ( object compareTo ) : bool
compareTo object
return bool
        protected void BaseAdd(ConfigurationElement element, bool throwIfExists)
        {
            if (IsReadOnly())
            {
                throw new ConfigurationErrorsException("Collection is read only.");
            }

            if (IsAlternate)
            {
                list.Insert(inheritedLimitIndex, element);
                inheritedLimitIndex++;
            }
            else
            {
                int old_index = IndexOfKey(GetElementKey(element));
                if (old_index >= 0)
                {
                    if (element.Equals(list [old_index]))
                    {
                        return;
                    }
                    if (throwIfExists)
                    {
                        throw new ConfigurationErrorsException("Duplicate element in collection");
                    }
                    list.RemoveAt(old_index);
                }
                list.Add(element);
            }

            modified = true;
        }
 private void BaseAdd(ConfigurationElement element, bool throwIfExists, bool ignoreLocks)
 {
     bool flagAsReplaced = false;
     bool internalAddToEnd = this.internalAddToEnd;
     if (this.IsReadOnly())
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_read_only"));
     }
     if (base.LockItem && !ignoreLocks)
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_locked", new object[] { this._addElement }));
     }
     object elementKeyInternal = this.GetElementKeyInternal(element);
     int index = -1;
     for (int i = 0; i < this._items.Count; i++)
     {
         Entry entry = (Entry) this._items[i];
         if (this.CompareKeys(elementKeyInternal, entry.GetKey(this)))
         {
             if (((entry._value != null) && entry._value.LockItem) && !ignoreLocks)
             {
                 throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_collection_item_locked"));
             }
             if ((entry._entryType != EntryType.Removed) && throwIfExists)
             {
                 if (!element.Equals(entry._value))
                 {
                     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_collection_entry_already_exists", new object[] { elementKeyInternal }), element.PropertyFileName(""), element.PropertyLineNumber(""));
                 }
                 entry._value = element;
                 return;
             }
             if (entry._entryType != EntryType.Added)
             {
                 if (((this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap) || (this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate)) && ((entry._entryType == EntryType.Removed) && (this._removedItemCount > 0)))
                 {
                     this._removedItemCount--;
                 }
                 entry._entryType = EntryType.Replaced;
                 flagAsReplaced = true;
             }
             if (!internalAddToEnd && (this.CollectionType != ConfigurationElementCollectionType.AddRemoveClearMapAlternate))
             {
                 if (!ignoreLocks)
                 {
                     element.HandleLockedAttributes(entry._value);
                     element.MergeLocks(entry._value);
                 }
                 entry._value = element;
                 this.bModified = true;
                 return;
             }
             index = i;
             if (entry._entryType == EntryType.Added)
             {
                 internalAddToEnd = true;
             }
             break;
         }
     }
     if (index >= 0)
     {
         this._items.RemoveAt(index);
         if ((this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate) && (index > ((this.Count + this._removedItemCount) - this._inheritedCount)))
         {
             this._inheritedCount--;
         }
     }
     this.BaseAddInternal(internalAddToEnd ? -1 : index, element, flagAsReplaced, ignoreLocks);
     this.bModified = true;
 }
 private void BaseAdd(int index, ConfigurationElement element, bool ignoreLocks)
 {
     if (this.IsReadOnly())
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_read_only"));
     }
     if (index < -1)
     {
         throw new ConfigurationErrorsException(System.Configuration.SR.GetString("IndexOutOfRange", new object[] { index }));
     }
     if ((index != -1) && ((this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap) || (this.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate)))
     {
         int num = 0;
         if (index > 0)
         {
             foreach (Entry entry in this._items)
             {
                 if (entry._entryType != EntryType.Removed)
                 {
                     index--;
                 }
                 if (index == 0)
                 {
                     break;
                 }
                 num++;
             }
             index = ++num;
         }
         object elementKeyInternal = this.GetElementKeyInternal(element);
         foreach (Entry entry2 in this._items)
         {
             if (this.CompareKeys(elementKeyInternal, entry2.GetKey(this)) && (entry2._entryType != EntryType.Removed))
             {
                 if (!element.Equals(entry2._value))
                 {
                     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_collection_entry_already_exists", new object[] { elementKeyInternal }), element.PropertyFileName(""), element.PropertyLineNumber(""));
                 }
                 return;
             }
         }
     }
     this.BaseAddInternal(index, element, false, ignoreLocks);
 }
		protected void BaseAdd (ConfigurationElement element, bool throwIfExists)
		{
			if (IsReadOnly ())
				throw new ConfigurationErrorsException ("Collection is read only.");
			
			if (IsAlternate) {
				list.Insert (inheritedLimitIndex, element);
				inheritedLimitIndex++;
			}
			else {
				int old_index = IndexOfKey (GetElementKey (element));
				if (old_index >= 0) {
					if (element.Equals (list [old_index]))
						return;
					if (throwIfExists)
						throw new ConfigurationErrorsException ("Duplicate element in collection");
					list.RemoveAt (old_index);
				}
				list.Add (element);
			}

			modified = true;
		}
        private void BaseAdd(int index, ConfigurationElement element, bool ignoreLocks)
        {
            if (IsReadOnly())
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_read_only));
            }
            if (index < -1)
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.IndexOutOfRange, index));
            }

            if ((index != -1) &&
                (CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap ||
                CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate))
            {

                // If it's an AddRemoveClearMap*** collection, turn the index passed into into a real internal index
                int realIndex = 0;

                if (index > 0)
                {
                    foreach (Entry entryfound in _items)
                    {
                        if (entryfound._entryType != EntryType.Removed)
                        {
                            index--;
                        }
                        if (index == 0)
                        {
                            break;
                        }
                        realIndex++;
                    }
                    index = ++realIndex;
                }
                // check for duplicates
                Object key = GetElementKeyInternal(element);
                foreach (Entry entry in _items)
                {
                    if (CompareKeys(key, entry.GetKey(this)))
                    {
                        if (entry._entryType != EntryType.Removed)
                        {
                            if (!element.Equals(entry._value))
                            {
                                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_collection_entry_already_exists, key),
                                        element.PropertyFileName(""), element.PropertyLineNumber(""));
                            }
                            return;
                        }
                    }
                }

            }

            BaseAddInternal(index, element, false, ignoreLocks);
        }
        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)
                        {
                            // this is a special case for defect number 529517 to emulate everett behavior
                            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;
        }