internal void MergeLocks(ConfigurationElement source) {
if (source != null) {
_fItemLocked = ((source._fItemLocked & ConfigurationValueFlags.Locked) != 0) ?
(ConfigurationValueFlags.Inherited | source._fItemLocked) : _fItemLocked;
if (source._lockedAttributesList != null) {
if (_lockedAttributesList == null) {
_lockedAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedAttributes);
}
foreach (string key in source._lockedAttributesList)
_lockedAttributesList.Add(key, ConfigurationValueFlags.Inherited); // Mark entry as from the parent - read only
}
if (source._lockedAllExceptAttributesList != null) {
if (_lockedAllExceptAttributesList == null) {
_lockedAllExceptAttributesList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedExceptionList, String.Empty, source._lockedAllExceptAttributesList);
}
StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptAttributesList, source._lockedAllExceptAttributesList);
_lockedAllExceptAttributesList.ClearInternal(false);
foreach (string key in intersectionCollection) {
_lockedAllExceptAttributesList.Add(key, ConfigurationValueFlags.Default);
}
}
if (source._lockedElementsList != null) {
if (_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 = source.ElementTagName; // Default collections don't know there tag name
if (collection._lockedElementsList == null) {
collection._lockedElementsList = _lockedElementsList; //point to the same instance of the collection from parent
}
}
}
foreach (string key in source._lockedElementsList) {
_lockedElementsList.Add(key, ConfigurationValueFlags.Inherited); // Mark entry as from the parent - read only
if (collection != null) {
collection._lockedElementsList.Add(key, ConfigurationValueFlags.Inherited); // add the local copy
}
}
}
if (source._lockedAllExceptElementsList != null) {
if (_lockedAllExceptElementsList == null || _lockedAllExceptElementsList.Count == 0) {
_lockedAllExceptElementsList = new ConfigurationLockCollection(this, ConfigurationLockCollectionType.LockedElementsExceptionList, source._elementTagName, source._lockedAllExceptElementsList);
}
StringCollection intersectionCollection = IntersectLockCollections(_lockedAllExceptElementsList, source._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) {
// point default collection to the parent collection
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
}
if (_lockedAllExceptElementsList.HasParentElements) {
foreach (ConfigurationProperty prop in Properties) {
if ((!_lockedAllExceptElementsList.Contains(prop.Name)) &&
typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
((ConfigurationElement)this[prop]).SetLocked();
}
}
}
}
}
}