System.Configuration.ConfigurationElement.Reset C# (CSharp) Метод

Reset() защищенный Метод

protected Reset ( ConfigurationElement parentElement ) : void
parentElement ConfigurationElement
Результат void
        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);
                        }
                    }
                }
            }
        }

Usage Example

        protected internal override void Reset(ConfigurationElement parentElement)
        {
            bool basic = IsBasic;

            ConfigurationElementCollection parent = (ConfigurationElementCollection)parentElement;

            for (int n = 0; n < parent.Count; n++)
            {
                ConfigurationElement parentItem = parent.BaseGet(n);
                ConfigurationElement item       = CreateNewElementInternal(null);
                item.Reset(parentItem);
                BaseAdd(item);

                if (basic)
                {
                    if (inherited == null)
                    {
                        inherited = new ArrayList();
                    }
                    inherited.Add(item);
                }
            }
            if (IsAlternate)
            {
                inheritedLimitIndex = 0;
            }
            else
            {
                inheritedLimitIndex = Count - 1;
            }
            modified = false;
        }