Source/NFX/Environment/ConfigNode.cs
/// <summary>
/// Merges child sections from another node into this one. Another node may belong to a different configuration instance.
/// This method ignores override flags and merges nodes regardless
/// </summary>
Merges child sections from another node into this one. Another node may belong to a different configuration instance.
This method ignores override flags and merges nodes regardless
Merges child sections from another node into this one . Another node may belong to a different configuration instance . This method ignores override flags and merges nodes regardless
public void MergeSections(IConfigSectionNode other, NodeOverrideRules rules = null)
        {
          if (other==null || !other.Exists) return;
          checkCanModify();
          if (rules==null) rules = NodeOverrideRules.Default;
          var children = this.Children;
          var osects = other.Children;
          var clear = other[rules.SectionClearName].Exists;
          if (clear) this.DeleteAllChildren();
          foreach(var osect in osects)
          {
            if (osect.IsSameName(rules.SectionClearName))
              continue;
            var match = children.Where(child =>
                                 child.IsSameName(osect) &&
                                 child.AttrByName( rules.SectionMatchAttrName ).Value
                                 .EqualsIgnoreCase(osect.AttrByName(rules.SectionMatchAttrName).Value)).FirstOrDefault();
            var append = match == null;
            if (!append)
             append = rules.AppendSectionsWithoutMatchAttr &&
                      osect.AttrByName(rules.SectionMatchAttrName).Value.IsNullOrWhiteSpace();
            if (append)
              AddChildNode(osect.Name, osect.VerbatimValue).OverrideBy(osect, rules);
            else
              match.OverrideBy(osect, rules);
          }
        }
public void MergeSections ( IConfigSectionNode other , NodeOverrideRules rules = null ) { if ( other == null || ! other . Exists ) return ; checkCanModify ( ) ; if ( rules == null ) rules = NodeOverrideRules . Default ; var children = this . Children ; var osects = other . Children ; var clear = other [ rules . SectionClearName ] . Exists ; if ( clear ) this . DeleteAllChildren ( ) ; foreach ( var osect in osects ) { if ( osect . IsSameName ( rules . SectionClearName ) ) continue ; var match = children . Where ( child => child . IsSameName ( osect ) && child . AttrByName ( rules . SectionMatchAttrName ) . Value . EqualsIgnoreCase ( osect . AttrByName ( rules . SectionMatchAttrName ) . Value ) ) . FirstOrDefault ( ) ; var append = match == null ; if ( ! append ) append = rules . AppendSectionsWithoutMatchAttr && osect . AttrByName ( rules . SectionMatchAttrName ) . Value . IsNullOrWhiteSpace ( ) ; if ( append ) AddChildNode ( osect . Name , osect . VerbatimValue ) . OverrideBy ( osect , rules ) ; else match . OverrideBy ( osect , rules ) ; } }
Merges child sections from another node into this one.
Merges child sections from another node into this one .
//thread safe //thread safe //var matches = children.Where(child => child.IsSameName(osect)).ToList(); //if (matches.Count>1) //{ //  matches = matches.Where(child => child.AttrByName( rules.SectionMatchAttrName).ValueAsString() //                                                      .EqualsIgnoreCase(osect.AttrByName(rules.SectionMatchAttrName).ValueAsString())).ToList(); //} //if (matches.Count>0) // matches[0].OverrideBy(osect, rules); //else // AddChildNode(osect.Name, osect.VerbatimValue).OverrideBy(osect, rules); //20160329 DKh
other
IConfigSectionNode
rules
NodeOverrideRules