protected internal virtual void Reset(ConfigurationElement parentElement) {
Values.Clear();
ResetLockLists(parentElement);
ConfigurationPropertyCollection props = Properties; // Force the bag to be up to date
_bElementPresent = false;
if (parentElement == null) {
InitializeDefault();
}
else {
bool hasAnyChildElements = false;
ConfigurationPropertyCollection collectionKeys = null;
for (int index = 0; index < parentElement.Values.Count; index++) {
string key = parentElement.Values.GetKey(index);
ConfigurationValue ConfigValue = parentElement.Values.GetConfigValue(index);
object value = (ConfigValue != null) ? ConfigValue.Value : null;
PropertySourceInfo sourceInfo = (ConfigValue != null) ? ConfigValue.SourceInfo : null;
ConfigurationProperty prop = (ConfigurationProperty)parentElement.Properties[key];
if (prop == null || ((collectionKeys != null) && !collectionKeys.Contains(prop.Name))) {
continue;
}
if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
hasAnyChildElements = true;
}
else {
ConfigurationValueFlags flags = ConfigurationValueFlags.Inherited |
(((_lockedAttributesList != null) &&
(_lockedAttributesList.Contains(key) ||
_lockedAttributesList.Contains(LockAll)) ||
(_lockedAllExceptAttributesList != null) &&
!_lockedAllExceptAttributesList.Contains(key)) ?
ConfigurationValueFlags.Locked : ConfigurationValueFlags.Default);
if (value != s_nullPropertyValue) {
// _values[key] = value;
_values.SetValue(key, value, flags, sourceInfo);
}
if (!props.Contains(key)) // this is for optional provider models keys
{
props.Add(prop);
_values.SetValue(key, value, flags, sourceInfo);
}
}
}
if (hasAnyChildElements) {
for (int index = 0; index < parentElement.Values.Count; index++) {
string key = parentElement.Values.GetKey(index);
object value = parentElement.Values[index];
ConfigurationProperty prop = (ConfigurationProperty)parentElement.Properties[key];
if ((prop != null) && typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
//((ConfigurationElement)value).SerializeToXmlElement(writer, prop.Name);
ConfigurationElement childElement = (ConfigurationElement)this[prop];
childElement.Reset((ConfigurationElement)value);
}
}
}
}
}