System.Configuration.ConfigurationElement.Equals C# (CSharp) Метод

Equals() публичный Метод

public Equals ( object compareTo ) : bool
compareTo object
Результат bool
        public override bool Equals(object compareTo) {
            ConfigurationElement compareToElem = compareTo as ConfigurationElement;

            if (compareToElem == null || 
                (compareTo.GetType() != this.GetType()) ||
                ((compareToElem != null) && (compareToElem.Properties.Count != this.Properties.Count))) {
                return false;
            }

            foreach (ConfigurationProperty configProperty in this.Properties) {

                if (!Object.Equals(Values[configProperty.Name], compareToElem.Values[configProperty.Name])) {
                    if (!(((Values[configProperty.Name] == null || 
                            Values[configProperty.Name] == s_nullPropertyValue) && 
                           Object.Equals(compareToElem.Values[configProperty.Name], configProperty.DefaultValue)) ||
                          ((compareToElem.Values[configProperty.Name] == null || 
                            compareToElem.Values[configProperty.Name] == s_nullPropertyValue) && 
                           Object.Equals(Values[configProperty.Name], configProperty.DefaultValue))))
                        return false;
                }
            }
            return true;
        }

Usage Example

        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;
        }
All Usage Examples Of System.Configuration.ConfigurationElement::Equals