System.Configuration.ConfigurationLockCollection.Add C# (CSharp) Method

Add() public method

public Add ( string name ) : void
name string
return void
        public void Add(string name) {

            if (((_thisElement.ItemLocked & ConfigurationValueFlags.Locked) != 0) &&
                ((_thisElement.ItemLocked & ConfigurationValueFlags.Inherited) != 0)) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_attribute_locked, name));
            }

            ConfigurationValueFlags flags = ConfigurationValueFlags.Modified;

            string attribToLockTrim = name.Trim(); 
            ConfigurationProperty propToLock = _thisElement.Properties[attribToLockTrim];
            if (propToLock == null && attribToLockTrim != LockAll) {
                ConfigurationElementCollection collection = _thisElement as ConfigurationElementCollection;
                if (collection == null && _thisElement.Properties.DefaultCollectionProperty != null) { // this is not a collection but it may contain a default collection
                    collection = _thisElement[_thisElement.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                }

                if (collection == null ||
                    _lockType == ConfigurationLockCollectionType.LockedAttributes || // If the collection type is not element then the lock is bogus
                    _lockType == ConfigurationLockCollectionType.LockedExceptionList) {
                    _thisElement.ReportInvalidLock(attribToLockTrim, _lockType, null, null);
                }
                else if (!collection.IsLockableElement(attribToLockTrim)) {
                    _thisElement.ReportInvalidLock(attribToLockTrim, _lockType, null, collection.LockableElements);
                }
            }
            else { // the lock is in the property bag but is it the correct type?
                if (propToLock != null && propToLock.IsRequired)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_required_attribute_lock_attempt, propToLock.Name));

                if (attribToLockTrim != LockAll) {
                    if ((_lockType == ConfigurationLockCollectionType.LockedElements) ||
                         (_lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)) {
                        // If it is an element then it must be derived from ConfigurationElement
                        if (!typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) {
                            _thisElement.ReportInvalidLock(attribToLockTrim, _lockType, null, null);
                        }
                    }
                    else {
                        // if it is a property then it cannot be derived from ConfigurationElement
                        if (typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) {
                            _thisElement.ReportInvalidLock(attribToLockTrim, _lockType, null, null);
                        }
                    }
                }
            }

            if (internalDictionary.Contains(name)) {
                flags = ConfigurationValueFlags.Modified | (ConfigurationValueFlags)internalDictionary[name];
                internalDictionary.Remove(name); // not from parent
                internalArraylist.Remove(name);
            }
            internalDictionary.Add(name, flags); // not from parent
            internalArraylist.Add(name);
            _bModified = true;
        }

Same methods

ConfigurationLockCollection::Add ( string name, ConfigurationValueFlags flags ) : void

Usage Example

 internal ConfigurationLockCollection UnMergeLockList(ConfigurationLockCollection sourceLockList, ConfigurationLockCollection parentLockList, ConfigurationSaveMode saveMode)
 {
     if (!sourceLockList.ExceptionList)
     {
         switch (saveMode)
         {
             case ConfigurationSaveMode.Modified:
             {
                 ConfigurationLockCollection locks = new ConfigurationLockCollection(this, sourceLockList.LockType);
                 foreach (string str in sourceLockList)
                 {
                     if (!parentLockList.Contains(str) || sourceLockList.IsValueModified(str))
                     {
                         locks.Add(str, ConfigurationValueFlags.Default);
                     }
                 }
                 return locks;
             }
             case ConfigurationSaveMode.Minimal:
             {
                 ConfigurationLockCollection locks2 = new ConfigurationLockCollection(this, sourceLockList.LockType);
                 foreach (string str2 in sourceLockList)
                 {
                     if (!parentLockList.Contains(str2))
                     {
                         locks2.Add(str2, ConfigurationValueFlags.Default);
                     }
                 }
                 return locks2;
             }
         }
         return sourceLockList;
     }
     if ((saveMode == ConfigurationSaveMode.Modified) || (saveMode == ConfigurationSaveMode.Minimal))
     {
         bool flag = false;
         if (sourceLockList.Count == parentLockList.Count)
         {
             flag = true;
             foreach (string str3 in sourceLockList)
             {
                 if (!parentLockList.Contains(str3) || (sourceLockList.IsValueModified(str3) && (saveMode == ConfigurationSaveMode.Modified)))
                 {
                     flag = false;
                 }
             }
         }
         if (flag)
         {
             return null;
         }
     }
     return sourceLockList;
 }
All Usage Examples Of System.Configuration.ConfigurationLockCollection::Add