internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) { ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo); BaseSet(key, configValue); }
internal void ChangeSourceInfo(string key, PropertySourceInfo sourceInfo) { ConfigurationValue configValue = this.GetConfigValue(key); if (configValue != null) { configValue.SourceInfo = sourceInfo; } }
internal void ChangeSourceInfo(string key, PropertySourceInfo sourceInfo) { ConfigurationValue configurationValue = GetConfigValue(key); if (configurationValue != null) { configurationValue.SourceInfo = sourceInfo; } }
private ConfigurationValue CreateConfigValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) { if (value != null) { if (value is ConfigurationElement) { _containsElement = true; ((ConfigurationElement)value).AssociateContext(_configRecord); } else if (value is InvalidPropValue) { _containsInvalidValue = true; } } ConfigurationValue configValue = new ConfigurationValue(value, valueFlags, sourceInfo); return configValue; }
private ConfigurationValue CreateConfigValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) { if (value != null) { if (value is ConfigurationElement) { _containsElement = true; ((ConfigurationElement)value).AssociateContext(_configRecord); } else { if (value is InvalidPropValue) { _containsInvalidValue = true; } } } ConfigurationValue configValue = new ConfigurationValue(value, valueFlags, sourceInfo); return(configValue); }
protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { ConfigurationPropertyCollection props = Properties; ConfigurationValue LockedAttributesList = null; ConfigurationValue LockedAllExceptList = null; ConfigurationValue LockedElementList = null; ConfigurationValue LockedAllElementsExceptList = null; bool ItemLockedLocally = false; _bElementPresent = true; ConfigurationElement defaultCollection = null; ConfigurationProperty defaultCollectionProperty = props != null ? props.DefaultCollectionProperty : null; if (defaultCollectionProperty != null) { defaultCollection = (ConfigurationElement)this[defaultCollectionProperty]; } // Process attributes _elementTagName = reader.Name; PropertySourceInfo rootInfo = new PropertySourceInfo(reader); _values.SetValue(reader.Name, null, ConfigurationValueFlags.Modified, rootInfo); _values.SetValue(DefaultCollectionPropertyName, defaultCollection, ConfigurationValueFlags.Modified, rootInfo); if ((_lockedElementsList != null && (_lockedElementsList.Contains(reader.Name) || (_lockedElementsList.Contains(LockAll) && reader.Name != ElementTagName))) || (_lockedAllExceptElementsList != null && _lockedAllExceptElementsList.Count != 0 && !_lockedAllExceptElementsList.Contains(reader.Name)) || ((_fItemLocked & ConfigurationValueFlags.Locked) != 0 && (_fItemLocked & ConfigurationValueFlags.Inherited) != 0) ) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_element_locked, reader.Name), reader); } if (reader.AttributeCount > 0) { while (reader.MoveToNextAttribute()) { String propertyName = reader.Name; if ((_lockedAttributesList != null && (_lockedAttributesList.Contains(propertyName) || _lockedAttributesList.Contains(LockAll))) || (_lockedAllExceptAttributesList != null && !_lockedAllExceptAttributesList.Contains(propertyName)) ) { if (propertyName != LockAttributesKey && propertyName != LockAllAttributesExceptKey) throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_attribute_locked, propertyName), reader); } ConfigurationProperty prop = props != null ? props[propertyName] : null; if (prop != null) { if (serializeCollectionKey && !prop.IsKey) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_attribute, propertyName), reader); } _values.SetValue(propertyName, DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader)); } // if (deserializing a remove OR an add that does not handle optional attributes) else if (propertyName == LockItemKey) { try { ItemLockedLocally = bool.Parse(reader.Value); } catch { throw new ConfigurationErrorsException(SR.GetString(SR.Config_invalid_boolean_attribute, propertyName), reader); } } else if (propertyName == LockAttributesKey) { LockedAttributesList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (propertyName == LockAllAttributesExceptKey) { LockedAllExceptList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (propertyName == LockElementsKey) { LockedElementList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (propertyName == LockAllElementsExceptKey) { LockedAllElementsExceptList = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else if (serializeCollectionKey || !OnDeserializeUnrecognizedAttribute(propertyName, reader.Value)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_attribute, propertyName), reader); } } } reader.MoveToElement(); // Check for nested elements. try { HybridDictionary nodeFound = new HybridDictionary(); if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { String propertyName = reader.Name; CheckLockedElement(propertyName, null); ConfigurationProperty prop = props != null ? props[propertyName] : null; if (prop != null) { if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) { if (nodeFound.Contains(propertyName)) throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_element_cannot_have_multiple_child_elements, propertyName), reader); nodeFound.Add(propertyName, propertyName); ConfigurationElement childElement = (ConfigurationElement)this[prop]; childElement.DeserializeElement(reader, serializeCollectionKey); // Validate the new element with the per-property Validator // Note that the per-type validator for childElement has been already executed as part of Deserialize ValidateElement(childElement, prop.Validator, false); } else { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_property_is_not_a_configuration_element, propertyName), reader); } } else if (!OnDeserializeUnrecognizedElement(propertyName, reader)) { // Let the default collection, if there is one, handle this node. if (defaultCollection == null || !defaultCollection.OnDeserializeUnrecognizedElement(propertyName, reader)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_element_name, propertyName), reader); } } } else if (reader.NodeType == XmlNodeType.EndElement) { break; } else if ((reader.NodeType == XmlNodeType.CDATA) || (reader.NodeType == XmlNodeType.Text)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_section_invalid_content), reader); } } } EnsureRequiredProperties(serializeCollectionKey); // Call the per-type validator for this object ValidateElement(this, null, false); } catch (ConfigurationException e) { // Catch the generic message from deserialization and include line info if necessary if (e.Filename == null || e.Filename.Length == 0) throw new ConfigurationErrorsException(e.Message, reader); // give it some info else throw e; } if (ItemLockedLocally) { SetLocked(); _fItemLocked = ConfigurationValueFlags.Locked; } if (LockedAttributesList != null) { if (_lockedAttributesList == null) _lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes); foreach (string key in ParseLockedAttributes(LockedAttributesList, ConfigurationLockCollectionType.LockedAttributes)) { if (!_lockedAttributesList.Contains(key)) _lockedAttributesList.Add(key, ConfigurationValueFlags.Default); // add the local copy else _lockedAttributesList.Add(key, ConfigurationValueFlags.Modified | ConfigurationValueFlags.Inherited); // add the local copy } } if (LockedAllExceptList != null) { ConfigurationLockCollection newCollection = ParseLockedAttributes(LockedAllExceptList, ConfigurationLockCollectionType.LockedExceptionList); if (_lockedAllExceptAttributesList == null) { _lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, String.Empty, newCollection); _lockedAllExceptAttributesList.ClearSeedList(); // Prevent the list from thinking this was set by a parent. } StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptAttributesList, newCollection); /* if (intersectionCollection.Count == 0) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_empty_lock_attributes_except_effective, LockAllAttributesExceptKey, LockedAllExceptList.Value, LockAttributesKey), LockedAllExceptList.SourceInfo.FileName, LockedAllExceptList.SourceInfo.LineNumber); } */ _lockedAllExceptAttributesList.ClearInternal(false); foreach (string key in intersectionCollection) { _lockedAllExceptAttributesList.Add(key, ConfigurationValueFlags.Default); } } if (LockedElementList != null) { if (_lockedElementsList == null) _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); ConfigurationLockCollection localLockedElementList = ParseLockedAttributes(LockedElementList, ConfigurationLockCollectionType.LockedElements); ConfigurationElementCollection collection = null; if (props.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection { collection = this[props.DefaultCollectionProperty] as ConfigurationElementCollection; if (collection != null && collection._lockedElementsList == null) collection._lockedElementsList = _lockedElementsList; } foreach (string key in localLockedElementList) { if (!_lockedElementsList.Contains(key)) { _lockedElementsList.Add(key, ConfigurationValueFlags.Default); // add the local copy ConfigurationProperty propToLock = Properties[key]; if (propToLock != null && typeof(ConfigurationElement).IsAssignableFrom(propToLock.Type)) { ((ConfigurationElement)this[key]).SetLocked(); } if (key == LockAll) { foreach (ConfigurationProperty prop in Properties) { if (!string.IsNullOrEmpty(prop.Name) && typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) { ((ConfigurationElement)this[prop]).SetLocked(); } } } } } } if (LockedAllElementsExceptList != null) { ConfigurationLockCollection newCollection = ParseLockedAttributes(LockedAllElementsExceptList, ConfigurationLockCollectionType.LockedElementsExceptionList); if (_lockedAllExceptElementsList == null) { _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, _elementTagName, newCollection); _lockedAllExceptElementsList.ClearSeedList(); } StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptElementsList, newCollection); ConfigurationElementCollection collection = null; if (props.DefaultCollectionProperty != null) // this is not a collection but it may contain a default collection { collection = this[props.DefaultCollectionProperty] as ConfigurationElementCollection; if (collection != null && collection._lockedAllExceptElementsList == null) collection._lockedAllExceptElementsList = _lockedAllExceptElementsList; } _lockedAllExceptElementsList.ClearInternal(false); foreach (string key in intersectionCollection) { if (!_lockedAllExceptElementsList.Contains(key) || key == ElementTagName) _lockedAllExceptElementsList.Add(key, ConfigurationValueFlags.Default); // add the local copy } foreach (ConfigurationProperty prop in Properties) { if (!(string.IsNullOrEmpty(prop.Name) || _lockedAllExceptElementsList.Contains(prop.Name)) && typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) { ((ConfigurationElement)this[prop]).SetLocked(); } } } // Make sure default collections use the same lock element lists if (defaultCollectionProperty != null) { defaultCollection = (ConfigurationElement)this[defaultCollectionProperty]; if (_lockedElementsList == null) { _lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); } defaultCollection._lockedElementsList = _lockedElementsList; if (_lockedAllExceptElementsList == null) { _lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name); _lockedAllExceptElementsList.ClearSeedList(); } defaultCollection._lockedAllExceptElementsList = _lockedAllExceptElementsList; } // This has to be the last thing to execute PostDeserialize(); }
internal ConfigurationValue(object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) { Value = value; ValueFlags = valueFlags; SourceInfo = sourceInfo; }
internal void ChangeSourceAndLineNumber(PropertySourceInfo sourceInformation) { _thisElement.Values.ChangeSourceInfo(_thisElement.ElementTagName, sourceInformation); }
/// <summary> /// Reads XML from the configuration file. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> that reads from the configuration file.</param><param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param><exception cref="T:System.Configuration.ConfigurationErrorsException">The element to read is locked.- or -An attribute of the current node is not recognized.- or -The lock status of the current node cannot be determined. </exception> protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { ConfigurationPropertyCollection properties = this.Properties; ConfigurationValue configurationValue1 = (ConfigurationValue) null; ConfigurationValue configurationValue2 = (ConfigurationValue) null; ConfigurationValue configurationValue3 = (ConfigurationValue) null; ConfigurationValue configurationValue4 = (ConfigurationValue) null; bool flag = false; this._bElementPresent = true; ConfigurationElement configurationElement1 = (ConfigurationElement) null; ConfigurationProperty index1 = properties != null ? properties.DefaultCollectionProperty : (ConfigurationProperty) null; if (index1 != null) configurationElement1 = (ConfigurationElement) this[index1]; this._elementTagName = reader.Name; PropertySourceInfo sourceInfo = new PropertySourceInfo(reader); this._values.SetValue(reader.Name, (object) null, ConfigurationValueFlags.Modified, sourceInfo); this._values.SetValue("", (object) configurationElement1, ConfigurationValueFlags.Modified, sourceInfo); if (this._lockedElementsList != null && (this._lockedElementsList.Contains(reader.Name) || this._lockedElementsList.Contains("*") && reader.Name != this.ElementTagName) || (this._lockedAllExceptElementsList != null && this._lockedAllExceptElementsList.Count != 0 && !this._lockedAllExceptElementsList.Contains(reader.Name) || (this._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default && (this._fItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_locked", new object[1] { (object) reader.Name }), reader); } else { if (reader.AttributeCount > 0) { while (reader.MoveToNextAttribute()) { string name = reader.Name; if ((this._lockedAttributesList != null && (this._lockedAttributesList.Contains(name) || this._lockedAttributesList.Contains("*")) || this._lockedAllExceptAttributesList != null && !this._lockedAllExceptAttributesList.Contains(name)) && (name != "lockAttributes" && name != "lockAllAttributesExcept")) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[1] { (object) name }), reader); } else { ConfigurationProperty prop = properties != null ? properties[name] : (ConfigurationProperty) null; if (prop != null) { if (serializeCollectionKey && !prop.IsKey) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[1] { (object) name }), reader); else this._values.SetValue(name, this.DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader)); } else if (name == "lockItem") { try { flag = bool.Parse(reader.Value); } catch { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_invalid_boolean_attribute", new object[1] { (object) name }), reader); } } else if (name == "lockAttributes") configurationValue1 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (name == "lockAllAttributesExcept") configurationValue2 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (name == "lockElements") configurationValue3 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (name == "lockAllElementsExcept") configurationValue4 = new ConfigurationValue((object) reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); else if (serializeCollectionKey || !this.OnDeserializeUnrecognizedAttribute(name, reader.Value)) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[1] { (object) name }), reader); } } } reader.MoveToElement(); try { HybridDictionary hybridDictionary = new HybridDictionary(); if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; this.CheckLockedElement(name, (XmlReader) null); ConfigurationProperty index2 = properties != null ? properties[name] : (ConfigurationProperty) null; if (index2 != null) { if (index2.IsConfigurationElementType) { if (hybridDictionary.Contains((object) name)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_cannot_have_multiple_child_elements", new object[1] { (object) name }), reader); } else { hybridDictionary.Add((object) name, (object) name); ConfigurationElement elem = (ConfigurationElement) this[index2]; elem.DeserializeElement(reader, serializeCollectionKey); ConfigurationElement.ValidateElement(elem, index2.Validator, false); } } else throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_property_is_not_a_configuration_element", new object[1] { (object) name }), reader); } else if (!this.OnDeserializeUnrecognizedElement(name, reader) && (configurationElement1 == null || !configurationElement1.OnDeserializeUnrecognizedElement(name, reader))) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_element_name", new object[1] { (object) name }), reader); } else if (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType == XmlNodeType.CDATA || reader.NodeType == XmlNodeType.Text) throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_section_invalid_content"), reader); } else break; } } this.EnsureRequiredProperties(serializeCollectionKey); ConfigurationElement.ValidateElement(this, (ConfigurationValidatorBase) null, false); } catch (ConfigurationException ex) { if (ex.Filename == null || ex.Filename.Length == 0) throw new ConfigurationErrorsException(ex.Message, reader); else throw ex; } if (flag) { this.SetLocked(); this._fItemLocked = ConfigurationValueFlags.Locked; } if (configurationValue1 != null) { if (this._lockedAttributesList == null) this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes); foreach (string name in this.ParseLockedAttributes(configurationValue1, ConfigurationLockCollectionType.LockedAttributes)) { if (!this._lockedAttributesList.Contains(name)) this._lockedAttributesList.Add(name, ConfigurationValueFlags.Default); else this._lockedAttributesList.Add(name, ConfigurationValueFlags.Inherited | ConfigurationValueFlags.Modified); } } if (configurationValue2 != null) { ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue2, ConfigurationLockCollectionType.LockedExceptionList); if (this._lockedAllExceptAttributesList == null) { this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, configurationLockCollection); this._lockedAllExceptAttributesList.ClearSeedList(); } StringCollection stringCollection = this.IntersectLockCollections(this._lockedAllExceptAttributesList, configurationLockCollection); this._lockedAllExceptAttributesList.ClearInternal(false); foreach (string name in stringCollection) this._lockedAllExceptAttributesList.Add(name, ConfigurationValueFlags.Default); } if (configurationValue3 != null) { if (this._lockedElementsList == null) this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue3, ConfigurationLockCollectionType.LockedElements); if (properties.DefaultCollectionProperty != null) { ConfigurationElementCollection elementCollection = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if (elementCollection != null && elementCollection._lockedElementsList == null) elementCollection._lockedElementsList = this._lockedElementsList; } foreach (string name in configurationLockCollection) { if (!this._lockedElementsList.Contains(name)) { this._lockedElementsList.Add(name, ConfigurationValueFlags.Default); ConfigurationProperty configurationProperty = this.Properties[name]; if (configurationProperty != null && typeof (ConfigurationElement).IsAssignableFrom(configurationProperty.Type)) ((ConfigurationElement) this[name]).SetLocked(); if (name == "*") { foreach (ConfigurationProperty index2 in this.Properties) { if (!string.IsNullOrEmpty(index2.Name) && index2.IsConfigurationElementType) ((ConfigurationElement) this[index2]).SetLocked(); } } } } } if (configurationValue4 != null) { ConfigurationLockCollection configurationLockCollection = this.ParseLockedAttributes(configurationValue4, ConfigurationLockCollectionType.LockedElementsExceptionList); if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, this._elementTagName, configurationLockCollection); this._lockedAllExceptElementsList.ClearSeedList(); } StringCollection stringCollection = this.IntersectLockCollections(this._lockedAllExceptElementsList, configurationLockCollection); if (properties.DefaultCollectionProperty != null) { ConfigurationElementCollection elementCollection = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if (elementCollection != null && elementCollection._lockedAllExceptElementsList == null) elementCollection._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } this._lockedAllExceptElementsList.ClearInternal(false); foreach (string name in stringCollection) { if (!this._lockedAllExceptElementsList.Contains(name) || name == this.ElementTagName) this._lockedAllExceptElementsList.Add(name, ConfigurationValueFlags.Default); } foreach (ConfigurationProperty index2 in this.Properties) { if (!string.IsNullOrEmpty(index2.Name) && !this._lockedAllExceptElementsList.Contains(index2.Name) && index2.IsConfigurationElementType) ((ConfigurationElement) this[index2]).SetLocked(); } } if (index1 != null) { ConfigurationElement configurationElement2 = (ConfigurationElement) this[index1]; if (this._lockedElementsList == null) this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); configurationElement2._lockedElementsList = this._lockedElementsList; if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name); this._lockedAllExceptElementsList.ClearSeedList(); } configurationElement2._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } this.PostDeserialize(); } }
private void SetValue(int index, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) { ConfigurationValue configValue = CreateConfigValue(value, valueFlags, sourceInfo); BaseSet(index, configValue); }
internal void SetValue(string key, object value, ConfigurationValueFlags valueFlags, PropertySourceInfo sourceInfo) { ConfigurationValue value2 = this.CreateConfigValue(value, valueFlags, sourceInfo); base.BaseSet(key, value2); }
protected internal virtual void DeserializeElement(XmlReader reader, bool serializeCollectionKey) { ConfigurationPropertyCollection properties = this.Properties; ConfigurationValue value2 = null; ConfigurationValue value3 = null; ConfigurationValue value4 = null; ConfigurationValue value5 = null; bool flag = false; this._bElementPresent = true; ConfigurationElement element = null; ConfigurationProperty property = (properties != null) ? properties.DefaultCollectionProperty : null; if (property != null) { element = (ConfigurationElement) this[property]; } this._elementTagName = reader.Name; PropertySourceInfo sourceInfo = new PropertySourceInfo(reader); this._values.SetValue(reader.Name, null, ConfigurationValueFlags.Modified, sourceInfo); this._values.SetValue("", element, ConfigurationValueFlags.Modified, sourceInfo); if (((this._lockedElementsList != null) && (this._lockedElementsList.Contains(reader.Name) || (this._lockedElementsList.Contains("*") && (reader.Name != this.ElementTagName)))) || ((((this._lockedAllExceptElementsList != null) && (this._lockedAllExceptElementsList.Count != 0)) && !this._lockedAllExceptElementsList.Contains(reader.Name)) || (((this._fItemLocked & ConfigurationValueFlags.Locked) != ConfigurationValueFlags.Default) && ((this._fItemLocked & ConfigurationValueFlags.Inherited) != ConfigurationValueFlags.Default)))) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_locked", new object[] { reader.Name }), reader); } if (reader.AttributeCount > 0) { while (reader.MoveToNextAttribute()) { string name = reader.Name; if ((((this._lockedAttributesList != null) && (this._lockedAttributesList.Contains(name) || this._lockedAttributesList.Contains("*"))) || ((this._lockedAllExceptAttributesList != null) && !this._lockedAllExceptAttributesList.Contains(name))) && ((name != "lockAttributes") && (name != "lockAllAttributesExcept"))) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_attribute_locked", new object[] { name }), reader); } ConfigurationProperty prop = (properties != null) ? properties[name] : null; if (prop != null) { if (serializeCollectionKey && !prop.IsKey) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[] { name }), reader); } this._values.SetValue(name, this.DeserializePropertyValue(prop, reader), ConfigurationValueFlags.Modified, new PropertySourceInfo(reader)); } else { if (name == "lockItem") { try { flag = bool.Parse(reader.Value); continue; } catch { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_invalid_boolean_attribute", new object[] { name }), reader); } } if (name == "lockAttributes") { value2 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); } else { if (name == "lockAllAttributesExcept") { value3 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); continue; } if (name == "lockElements") { value4 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); continue; } if (name == "lockAllElementsExcept") { value5 = new ConfigurationValue(reader.Value, ConfigurationValueFlags.Default, new PropertySourceInfo(reader)); continue; } if (serializeCollectionKey || !this.OnDeserializeUnrecognizedAttribute(name, reader.Value)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_attribute", new object[] { name }), reader); } } } } } reader.MoveToElement(); try { HybridDictionary dictionary = new HybridDictionary(); if (!reader.IsEmptyElement) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { string elementName = reader.Name; this.CheckLockedElement(elementName, null); ConfigurationProperty property3 = (properties != null) ? properties[elementName] : null; if (property3 == null) { if (!this.OnDeserializeUnrecognizedElement(elementName, reader) && ((element == null) || !element.OnDeserializeUnrecognizedElement(elementName, reader))) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_unrecognized_element_name", new object[] { elementName }), reader); } } else { if (!property3.IsConfigurationElementType) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_property_is_not_a_configuration_element", new object[] { elementName }), reader); } if (dictionary.Contains(elementName)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_element_cannot_have_multiple_child_elements", new object[] { elementName }), reader); } dictionary.Add(elementName, elementName); ConfigurationElement elem = (ConfigurationElement) this[property3]; elem.DeserializeElement(reader, serializeCollectionKey); ValidateElement(elem, property3.Validator, false); } } else { if (reader.NodeType == XmlNodeType.EndElement) { break; } if ((reader.NodeType == XmlNodeType.CDATA) || (reader.NodeType == XmlNodeType.Text)) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_base_section_invalid_content"), reader); } } } } this.EnsureRequiredProperties(serializeCollectionKey); ValidateElement(this, null, false); } catch (ConfigurationException exception) { if ((exception.Filename != null) && (exception.Filename.Length != 0)) { throw exception; } throw new ConfigurationErrorsException(exception.Message, reader); } if (flag) { this.SetLocked(); this._fItemLocked = ConfigurationValueFlags.Locked; } if (value2 != null) { if (this._lockedAttributesList == null) { this._lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes); } foreach (string str3 in this.ParseLockedAttributes(value2, ConfigurationLockCollectionType.LockedAttributes)) { if (!this._lockedAttributesList.Contains(str3)) { this._lockedAttributesList.Add(str3, ConfigurationValueFlags.Default); } else { this._lockedAttributesList.Add(str3, ConfigurationValueFlags.Modified | ConfigurationValueFlags.Inherited); } } } if (value3 != null) { ConfigurationLockCollection parentCollection = this.ParseLockedAttributes(value3, ConfigurationLockCollectionType.LockedExceptionList); if (this._lockedAllExceptAttributesList == null) { this._lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, string.Empty, parentCollection); this._lockedAllExceptAttributesList.ClearSeedList(); } StringCollection strings = this.IntersectLockCollections(this._lockedAllExceptAttributesList, parentCollection); this._lockedAllExceptAttributesList.ClearInternal(false); foreach (string str4 in strings) { this._lockedAllExceptAttributesList.Add(str4, ConfigurationValueFlags.Default); } } if (value4 != null) { if (this._lockedElementsList == null) { this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); } ConfigurationLockCollection locks2 = this.ParseLockedAttributes(value4, ConfigurationLockCollectionType.LockedElements); ConfigurationElementCollection elements = null; if (properties.DefaultCollectionProperty != null) { elements = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if ((elements != null) && (elements._lockedElementsList == null)) { elements._lockedElementsList = this._lockedElementsList; } } foreach (string str5 in locks2) { if (!this._lockedElementsList.Contains(str5)) { this._lockedElementsList.Add(str5, ConfigurationValueFlags.Default); ConfigurationProperty property4 = this.Properties[str5]; if ((property4 != null) && typeof(ConfigurationElement).IsAssignableFrom(property4.Type)) { ((ConfigurationElement) this[str5]).SetLocked(); } if (str5 == "*") { foreach (ConfigurationProperty property5 in this.Properties) { if (!string.IsNullOrEmpty(property5.Name) && property5.IsConfigurationElementType) { ((ConfigurationElement) this[property5]).SetLocked(); } } } } } } if (value5 != null) { ConfigurationLockCollection locks3 = this.ParseLockedAttributes(value5, ConfigurationLockCollectionType.LockedElementsExceptionList); if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, this._elementTagName, locks3); this._lockedAllExceptElementsList.ClearSeedList(); } StringCollection strings2 = this.IntersectLockCollections(this._lockedAllExceptElementsList, locks3); ConfigurationElementCollection elements2 = null; if (properties.DefaultCollectionProperty != null) { elements2 = this[properties.DefaultCollectionProperty] as ConfigurationElementCollection; if ((elements2 != null) && (elements2._lockedAllExceptElementsList == null)) { elements2._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } } this._lockedAllExceptElementsList.ClearInternal(false); foreach (string str6 in strings2) { if (!this._lockedAllExceptElementsList.Contains(str6) || (str6 == this.ElementTagName)) { this._lockedAllExceptElementsList.Add(str6, ConfigurationValueFlags.Default); } } foreach (ConfigurationProperty property6 in this.Properties) { if ((!string.IsNullOrEmpty(property6.Name) && !this._lockedAllExceptElementsList.Contains(property6.Name)) && property6.IsConfigurationElementType) { ((ConfigurationElement) this[property6]).SetLocked(); } } } if (property != null) { element = (ConfigurationElement) this[property]; if (this._lockedElementsList == null) { this._lockedElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElements); } element._lockedElementsList = this._lockedElementsList; if (this._lockedAllExceptElementsList == null) { this._lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, reader.Name); this._lockedAllExceptElementsList.ClearSeedList(); } element._lockedAllExceptElementsList = this._lockedAllExceptElementsList; } this.PostDeserialize(); }