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

public Add ( string name ) : void
name string
Результат void
 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;
 }
 private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType)
 {
     ConfigurationLockCollection locks = new ConfigurationLockCollection(this, lockType);
     string str = (string) value.Value;
     if (string.IsNullOrEmpty(str))
     {
         if (lockType == ConfigurationLockCollectionType.LockedAttributes)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[] { "lockAttributes" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
         if (lockType == ConfigurationLockCollectionType.LockedElements)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[] { "lockElements" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
         if (lockType == ConfigurationLockCollectionType.LockedExceptionList)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_attributes_except", new object[] { "lockAllAttributesExcept", "lockAttributes" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
         if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_element_except", new object[] { "lockAllElementsExcept", "lockElements" }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
         }
     }
     foreach (string str2 in str.Split(new char[] { ',', ':', ';' }))
     {
         string str3 = str2.Trim();
         if (!string.IsNullOrEmpty(str3))
         {
             if (((lockType != ConfigurationLockCollectionType.LockedElements) && (lockType != ConfigurationLockCollectionType.LockedAttributes)) || (str3 != "*"))
             {
                 ConfigurationProperty property = this.Properties[str3];
                 if (((((property == null) || (str3 == "lockAttributes")) || ((str3 == "lockAllAttributesExcept") || (str3 == "lockElements"))) || (((lockType != ConfigurationLockCollectionType.LockedElements) && (lockType != ConfigurationLockCollectionType.LockedElementsExceptionList)) && typeof(ConfigurationElement).IsAssignableFrom(property.Type))) || (((lockType == ConfigurationLockCollectionType.LockedElements) || (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)) && !typeof(ConfigurationElement).IsAssignableFrom(property.Type)))
                 {
                     ConfigurationElementCollection elements = this as ConfigurationElementCollection;
                     if ((elements == null) && (this.Properties.DefaultCollectionProperty != null))
                     {
                         elements = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                     }
                     if (((elements == null) || (lockType == ConfigurationLockCollectionType.LockedAttributes)) || (lockType == ConfigurationLockCollectionType.LockedExceptionList))
                     {
                         this.ReportInvalidLock(str3, lockType, value, null);
                     }
                     else if (!elements.IsLockableElement(str3))
                     {
                         this.ReportInvalidLock(str3, lockType, value, elements.LockableElements);
                     }
                 }
                 if ((property != null) && property.IsRequired)
                 {
                     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_required_attribute_lock_attempt", new object[] { property.Name }));
                 }
             }
             locks.Add(str3, ConfigurationValueFlags.Default);
         }
     }
     return locks;
 }
        internal void ResetLockLists(ConfigurationElement parentElement) {
            _lockedAttributesList = null;
            _lockedAllExceptAttributesList = null;
            _lockedElementsList = null;
            _lockedAllExceptElementsList = null;

            if (parentElement != null) {
                _fItemLocked = ((parentElement._fItemLocked & ConfigurationValueFlags.Locked) != 0) ?
                    (ConfigurationValueFlags.Inherited | parentElement._fItemLocked) :
                    ConfigurationValueFlags.Default;

                if (parentElement._lockedAttributesList != null) {
                    _lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
                    foreach (string key in parentElement._lockedAttributesList)
                        _lockedAttributesList.Add(key, ConfigurationValueFlags.Inherited);  // Mark entry as from the parent - read only
                }
                if (parentElement._lockedAllExceptAttributesList != null) {
                    _lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, String.Empty, parentElement._lockedAllExceptAttributesList);
                }
                if (parentElement._lockedElementsList != null) {
                    _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements);

                    ConfigurationElementCollection collection = null;
                    if (Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                    {
                        collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                        if (collection != null) {
                            collection.internalElementTagName = parentElement.ElementTagName; // Default collections don't know there tag name
                            if (collection._lockedElementsList == null) {
                                collection._lockedElementsList = _lockedElementsList;
                            }
                        }
                    }

                    foreach (string key in parentElement._lockedElementsList) {
                        _lockedElementsList.Add(key, ConfigurationValueFlags.Inherited);  // Mark entry as from the parent - read only
                    }
                }

                if (parentElement._lockedAllExceptElementsList != null) {
                    _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, parentElement._elementTagName, parentElement._lockedAllExceptElementsList);

                    ConfigurationElementCollection collection = null;
                    if (Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                    {
                        collection = this[Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
                        if (collection != null && collection._lockedAllExceptElementsList == null) {
                            collection._lockedAllExceptElementsList = _lockedAllExceptElementsList;
                        }
                    }
                }
            }
        }
 internal ConfigurationLockCollection UnMergeLockList(
     ConfigurationLockCollection sourceLockList,
     ConfigurationLockCollection parentLockList,
     ConfigurationSaveMode saveMode) {
     if (sourceLockList.ExceptionList == false) {
         switch (saveMode) {
             case ConfigurationSaveMode.Modified: {
                     ConfigurationLockCollection tempLockList = new ConfigurationLockCollection(this, sourceLockList.LockType);
                     foreach (string lockedAttributeName in sourceLockList)
                         if (!parentLockList.Contains(lockedAttributeName) ||
                             sourceLockList.IsValueModified(lockedAttributeName)) {
                             tempLockList.Add(lockedAttributeName, ConfigurationValueFlags.Default);
                         }
                     return tempLockList;
                 }
             case ConfigurationSaveMode.Minimal: {
                     ConfigurationLockCollection tempLockList = new ConfigurationLockCollection(this, sourceLockList.LockType);
                     foreach (string lockedAttributeName in sourceLockList)
                         if (!parentLockList.Contains(lockedAttributeName)) {
                             tempLockList.Add(lockedAttributeName, ConfigurationValueFlags.Default);
                         }
                     return tempLockList;
                 }
         }
     }
     else {
         // exception list write out the entire collection unless the entire collection
         // came from the parent.
         if (saveMode == ConfigurationSaveMode.Modified || saveMode == ConfigurationSaveMode.Minimal) {
             bool sameAsParent = false;
             if (sourceLockList.Count == parentLockList.Count) {
                 sameAsParent = true;
                 foreach (string lockedAttributeName in sourceLockList) {
                     if (!parentLockList.Contains(lockedAttributeName) ||
                         (sourceLockList.IsValueModified(lockedAttributeName) &&
                          saveMode == ConfigurationSaveMode.Modified)) {
                         sameAsParent = false;
                     }
                 }
             }
             if (sameAsParent == true) {
                 return null;
             }
         }
     }
     return sourceLockList;
 }
        private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType) {
            // check that only actual properties are in the lock attribute
            ConfigurationLockCollection localLockedAttributesList = new ConfigurationLockCollection(this, lockType);
            string attributeList = (string)(value.Value);

            if (string.IsNullOrEmpty(attributeList)) {
                if (lockType == ConfigurationLockCollectionType.LockedAttributes)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
                if (lockType == ConfigurationLockCollectionType.LockedElements)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Empty_attribute, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
                if (lockType == ConfigurationLockCollectionType.LockedExceptionList)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_attributes_except, LockAllAttributesExceptKey, LockAttributesKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
                if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_element_except, LockAllElementsExceptKey, LockElementsKey), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
            }

            string[] attribsToLock = attributeList.Split(new char[] { ',', ':', ';' });
            foreach (string attribToLock in attribsToLock) {
                string attribToLockTrim = attribToLock.Trim();
                if (!String.IsNullOrEmpty(attribToLockTrim)) {
                    // validate that the locks are good
                    if (!((lockType == ConfigurationLockCollectionType.LockedElements ||
                         lockType == ConfigurationLockCollectionType.LockedAttributes) &&
                         attribToLockTrim == LockAll)) {
                        ConfigurationProperty propToLock = Properties[attribToLockTrim];

                        if (propToLock == null ||                                   // if the prop does not exist 
                            attribToLockTrim == LockAttributesKey ||                // or it is the lockattributes keyword
                            attribToLockTrim == LockAllAttributesExceptKey ||       // or it is the lockattributes keyword
                            attribToLockTrim == LockElementsKey ||                  // or it is the lockelements keyword
                            (lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedElementsExceptionList &&
                                typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) ||  // or if not locking elements but the property is a element
                            ((lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) &&
                             !typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) // or if locking elements but the property is not an element
                        ) {
                        // check to see if this is a collection and we are locking a collection element

                            ConfigurationElementCollection collection = this as ConfigurationElementCollection;
                            if (collection == null && Properties.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection
                            {
                                collection = this[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) {
                                ReportInvalidLock(attribToLockTrim, lockType, value, null);
                            }
                            else if (!collection.IsLockableElement(attribToLockTrim)) {
                                ReportInvalidLock(attribToLockTrim, lockType, value, collection.LockableElements);
                            }
                        }
                        if (propToLock != null && propToLock.IsRequired == true)
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_required_attribute_lock_attempt, propToLock.Name));
                    }


                    // concatenate the new attribute.
                    localLockedAttributesList.Add(attribToLockTrim, ConfigurationValueFlags.Default); // Mark as local
                }
            }
            return localLockedAttributesList;
        }
Пример #6
0
 private ConfigurationLockCollection ParseLockedAttributes(ConfigurationValue value, ConfigurationLockCollectionType lockType)
 {
     ConfigurationLockCollection configurationLockCollection = new ConfigurationLockCollection(this, lockType);
       string str1 = (string) value.Value;
       if (string.IsNullOrEmpty(str1))
       {
     if (lockType == ConfigurationLockCollectionType.LockedAttributes)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[1]
       {
     (object) "lockAttributes"
       }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
     else if (lockType == ConfigurationLockCollectionType.LockedElements)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Empty_attribute", new object[1]
       {
     (object) "lockElements"
       }), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
     else if (lockType == ConfigurationLockCollectionType.LockedExceptionList)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_attributes_except", (object) "lockAllAttributesExcept", (object) "lockAttributes"), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
     else if (lockType == ConfigurationLockCollectionType.LockedElementsExceptionList)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_empty_lock_element_except", (object) "lockAllElementsExcept", (object) "lockElements"), value.SourceInfo.FileName, value.SourceInfo.LineNumber);
       }
       string str2 = str1;
       char[] chArray = new char[3]
       {
     ',',
     ':',
     ';'
       };
       foreach (string str3 in str2.Split(chArray))
       {
     string index = str3.Trim();
     if (!string.IsNullOrEmpty(index))
     {
       if (lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedAttributes || !(index == "*"))
       {
     ConfigurationProperty configurationProperty = this.Properties[index];
     if (configurationProperty == null || index == "lockAttributes" || (index == "lockAllAttributesExcept" || index == "lockElements") || lockType != ConfigurationLockCollectionType.LockedElements && lockType != ConfigurationLockCollectionType.LockedElementsExceptionList && typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type) || (lockType == ConfigurationLockCollectionType.LockedElements || lockType == ConfigurationLockCollectionType.LockedElementsExceptionList) && !typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type))
     {
       ConfigurationElementCollection elementCollection = this as ConfigurationElementCollection;
       if (elementCollection == null && this.Properties.DefaultCollectionProperty != null)
         elementCollection = this[this.Properties.DefaultCollectionProperty] as ConfigurationElementCollection;
       if (elementCollection == null || lockType == ConfigurationLockCollectionType.LockedAttributes || lockType == ConfigurationLockCollectionType.LockedExceptionList)
         this.ReportInvalidLock(index, lockType, value, (string) null);
       else if (!elementCollection.IsLockableElement(index))
         this.ReportInvalidLock(index, lockType, value, elementCollection.LockableElements);
     }
     if (configurationProperty != null && configurationProperty.IsRequired)
       throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_required_attribute_lock_attempt", new object[1]
       {
         (object) configurationProperty.Name
       }));
       }
       configurationLockCollection.Add(index, ConfigurationValueFlags.Default);
     }
       }
       return configurationLockCollection;
 }
Пример #7
0
 internal ConfigurationLockCollection UnMergeLockList(ConfigurationLockCollection sourceLockList, ConfigurationLockCollection parentLockList, ConfigurationSaveMode saveMode)
 {
     if (!sourceLockList.ExceptionList)
       {
     switch (saveMode)
     {
       case ConfigurationSaveMode.Modified:
     ConfigurationLockCollection configurationLockCollection1 = new ConfigurationLockCollection(this, sourceLockList.LockType);
     foreach (string name in sourceLockList)
     {
       if (!parentLockList.Contains(name) || sourceLockList.IsValueModified(name))
         configurationLockCollection1.Add(name, ConfigurationValueFlags.Default);
     }
     return configurationLockCollection1;
       case ConfigurationSaveMode.Minimal:
     ConfigurationLockCollection configurationLockCollection2 = new ConfigurationLockCollection(this, sourceLockList.LockType);
     foreach (string name in sourceLockList)
     {
       if (!parentLockList.Contains(name))
         configurationLockCollection2.Add(name, ConfigurationValueFlags.Default);
     }
     return configurationLockCollection2;
     }
       }
       else if (saveMode == ConfigurationSaveMode.Modified || saveMode == ConfigurationSaveMode.Minimal)
       {
     bool flag = false;
     if (sourceLockList.Count == parentLockList.Count)
     {
       flag = true;
       foreach (string name in sourceLockList)
       {
     if (!parentLockList.Contains(name) || sourceLockList.IsValueModified(name) && saveMode == ConfigurationSaveMode.Modified)
       flag = false;
       }
     }
     if (flag)
       return (ConfigurationLockCollection) null;
       }
       return sourceLockList;
 }