Unmerge() 보호된 메소드

protected Unmerge ( ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode ) : void
sourceElement ConfigurationElement
parentElement ConfigurationElement
saveMode ConfigurationSaveMode
리턴 void
        protected internal override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode updateMode)
        {
            ConfigurationElementCollection source = (ConfigurationElementCollection)sourceElement;
            ConfigurationElementCollection parent = (ConfigurationElementCollection)parentElement;

            for (int n = 0; n < source.Count; n++)
            {
                ConfigurationElement sitem = source.BaseGet(n);
                object key = source.GetElementKey(sitem);
                ConfigurationElement pitem = parent != null?parent.BaseGet(key) as ConfigurationElement : null;

                ConfigurationElement nitem = CreateNewElementInternal(null);
                if (pitem != null && updateMode != ConfigurationSaveMode.Full)
                {
                    nitem.Unmerge(sitem, pitem, updateMode);
                    if (nitem.HasValues(pitem, updateMode))
                    {
                        BaseAdd(nitem);
                    }
                }
                else
                {
                    nitem.Unmerge(sitem, null, ConfigurationSaveMode.Full);
                    BaseAdd(nitem);
                }
            }

            if (updateMode == ConfigurationSaveMode.Full)
            {
                EmitClear = true;
            }
            else if (parent != null)
            {
                for (int n = 0; n < parent.Count; n++)
                {
                    ConfigurationElement pitem = parent.BaseGet(n);
                    object key = parent.GetElementKey(pitem);
                    if (source.IndexOfKey(key) == -1)
                    {
                        if (removed == null)
                        {
                            removed = new ArrayList();
                        }
                        removed.Add(pitem);
                    }
                }
            }
        }
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            if (((base.CurrentConfiguration != null) && (base.CurrentConfiguration.TargetFramework != null)) && !this.ShouldSerializeSectionInTargetVersion(base.CurrentConfiguration.TargetFramework))
            {
                return(string.Empty);
            }
            ConfigurationElement.ValidateElement(this, null, true);
            ConfigurationElement element = ConfigurationElement.CreateElement(base.GetType());

            element.Unmerge(this, parentElement, saveMode);
            StringWriter  w      = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter writer = new XmlTextWriter(w)
            {
                Formatting  = Formatting.Indented,
                Indentation = 4,
                IndentChar  = ' '
            };

            element.DataToWriteInternal = saveMode != ConfigurationSaveMode.Minimal;
            if ((base.CurrentConfiguration != null) && (base.CurrentConfiguration.TargetFramework != null))
            {
                base._configRecord.SectionsStack.Push(this);
            }
            element.SerializeToXmlElement(writer, name);
            if ((base.CurrentConfiguration != null) && (base.CurrentConfiguration.TargetFramework != null))
            {
                base._configRecord.SectionsStack.Pop();
            }
            writer.Flush();
            return(w.ToString());
        }
예제 #3
0
        protected internal virtual void Unmerge(
            ConfigurationElement source, ConfigurationElement parent,
            ConfigurationSaveMode updateMode)
        {
            if (parent != null && source.GetType() != parent.GetType())
            {
                throw new ConfigurationException("Can't unmerge two elements of different type");
            }

            foreach (PropertyInformation prop in source.ElementInformation.Properties)
            {
                if (prop.ValueOrigin == PropertyValueOrigin.Default)
                {
                    continue;
                }

                PropertyInformation unmergedProp = ElementInformation.Properties [prop.Name];

                object sourceValue = prop.Value;
                if (parent == null || !parent.HasValue(prop.Name))
                {
                    unmergedProp.Value = sourceValue;
                    continue;
                }
                else if (sourceValue != null)
                {
                    object parentValue = parent [prop.Name];
                    if (prop.IsElement)
                    {
                        if (parentValue != null)
                        {
                            ConfigurationElement copy = (ConfigurationElement)unmergedProp.Value;
                            copy.Unmerge((ConfigurationElement)sourceValue, (ConfigurationElement)parentValue, updateMode);
                        }
                        else
                        {
                            unmergedProp.Value = sourceValue;
                        }
                    }
                    else
                    {
                        if (!object.Equals(sourceValue, parentValue) ||
                            (updateMode == ConfigurationSaveMode.Full) ||
                            (updateMode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere))
                        {
                            unmergedProp.Value = sourceValue;
                        }
                    }
                }
            }
        }
예제 #4
0
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            ValidateElement(this, null, true);

            ConfigurationElement TempElement = CreateElement(this.GetType());

            TempElement.Unmerge(this, parentElement, saveMode);

            StringWriter  strWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter writer    = new XmlTextWriter(strWriter);

            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 4;
            writer.IndentChar  = ' ';
            TempElement.DataToWriteInternal = (saveMode != ConfigurationSaveMode.Minimal);
            TempElement.SerializeToXmlElement(writer, name);
            writer.Flush();
            return(strWriter.ToString());
        }
예제 #5
0
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            if (CurrentConfiguration != null &&
                CurrentConfiguration.TargetFramework != null &&
                !ShouldSerializeSectionInTargetVersion(CurrentConfiguration.TargetFramework))
            {
                return(string.Empty);
            }

            ValidateElement(this, null, true);

            ConfigurationElement TempElement = CreateElement(this.GetType());

            TempElement.Unmerge(this, parentElement, saveMode);

            StringWriter  strWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter writer    = new XmlTextWriter(strWriter);

            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 4;
            writer.IndentChar  = ' ';
            TempElement.DataToWriteInternal = (saveMode != ConfigurationSaveMode.Minimal);

            if (CurrentConfiguration != null && CurrentConfiguration.TargetFramework != null)
            {
                _configRecord.SectionsStack.Push(this);
            }

            TempElement.SerializeToXmlElement(writer, name);

            if (CurrentConfiguration != null && CurrentConfiguration.TargetFramework != null)
            {
                _configRecord.SectionsStack.Pop();
            }

            writer.Flush();
            return(strWriter.ToString());
        }
        protected internal virtual void Unmerge(
            ConfigurationElement sourceElement, ConfigurationElement parentElement,
            ConfigurationSaveMode saveMode)
        {
            if (parentElement != null && sourceElement.GetType() != parentElement.GetType())
            {
                throw new ConfigurationErrorsException("Can't unmerge two elements of different type");
            }

            bool isMinimalOrModified = saveMode == ConfigurationSaveMode.Minimal ||
                                       saveMode == ConfigurationSaveMode.Modified;

            foreach (PropertyInformation prop in sourceElement.ElementInformation.Properties)
            {
                if (prop.ValueOrigin == PropertyValueOrigin.Default)
                {
                    continue;
                }

                PropertyInformation unmergedProp = ElementInformation.Properties [prop.Name];

                object sourceValue = prop.Value;
                if (parentElement == null || !parentElement.HasValue(prop.Name))
                {
                    unmergedProp.Value = sourceValue;
                    continue;
                }

                if (sourceValue == null)
                {
                    continue;
                }

                object parentValue = parentElement [prop.Name];
                if (!prop.IsElement)
                {
                    if (!object.Equals(sourceValue, parentValue) ||
                        (saveMode == ConfigurationSaveMode.Full) ||
                        (saveMode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere))
                    {
                        unmergedProp.Value = sourceValue;
                    }
                    continue;
                }

                var sourceElementValue = (ConfigurationElement)sourceValue;
                if (isMinimalOrModified && !sourceElementValue.IsModified())
                {
                    continue;
                }
                if (parentValue == null)
                {
                    unmergedProp.Value = sourceValue;
                    continue;
                }

                var parentElementValue    = (ConfigurationElement)parentValue;
                ConfigurationElement copy = (ConfigurationElement)unmergedProp.Value;
                copy.Unmerge(sourceElementValue, parentElementValue, saveMode);
            }
        }