System.Configuration.ConfigurationPropertyCollection.Remove C# (CSharp) Method

Remove() public method

public Remove ( string name ) : bool
name string
return bool
        public bool Remove(string name) {
            for (int index = 0; index < _items.Count; index++) {
                ConfigurationProperty cp = (ConfigurationProperty)_items[index];

                if (cp.Name == name) {
                    _items.RemoveAt(index);
                    return true;
                }
            }
            return false;
        }

Usage Example

Example #1
0
        internal bool UpdatePropertyCollection()
        {
            bool      bIsModified = false;
            ArrayList removeList  = null;

            if (_propertyNameCollection != null)
            {
                // remove any data that has been delete from the collection
                foreach (ConfigurationProperty prop in _properties)
                {
                    if ((prop.Name != "name") && (prop.Name != "type"))
                    {
                        if (_propertyNameCollection.Get(prop.Name) != null)
                        {
                            continue;
                        }
                        if (removeList == null)
                        {
                            removeList = new ArrayList();
                        }

                        if ((Values.GetConfigValue(prop.Name).ValueFlags & ConfigurationValueFlags.Locked) != 0)
                        {
                            continue;
                        }
                        removeList.Add(prop.Name);
                        bIsModified = true;
                    }
                }

                if (removeList != null)
                {
                    foreach (string propName in removeList)
                    {
                        _properties.Remove(propName);
                    }
                }

                // then copy any data that has been changed in the collection
                foreach (string key in _propertyNameCollection)
                {
                    string valueInCollection = _propertyNameCollection[key];
                    string valueInBag        = GetProperty(key);

                    if ((valueInBag == null) || (valueInCollection != valueInBag)) // add new property
                    {
                        SetProperty(key, valueInCollection);
                        bIsModified = true;
                    }
                }
            }
            _propertyNameCollection = null;
            return(bIsModified);
        }