/// <summary> /// Initializes a new instance of the <see cref="SectionData"/> class /// from a previous instance of <see cref="SectionData"/>. /// </summary> /// <remarks> /// Data is deeply copied /// </remarks> /// <param name="ori"> /// The instance of the <see cref="SectionData"/> class /// used to create the new instance. /// </param> /// <param name="searchComparer"> /// Search comparer. /// </param> public SectionData(SectionData ori, IEqualityComparer<string> searchComparer = null) { SectionName = ori.SectionName; _searchComparer = searchComparer; _leadingComments = new List<string>(ori._leadingComments); _keyDataCollection = new KeyDataCollection(ori._keyDataCollection, searchComparer ?? ori._searchComparer); }
/// <summary> /// Merges otherSection into this, adding new keys if they don't exists /// or overwriting values if the key already exists. /// Comments get appended. /// </summary> /// <remarks> /// Comments are also merged but they are always added, not overwritten. /// </remarks> /// <param name="toMergeSection"></param> public void Merge(SectionData toMergeSection) { foreach (var comment in toMergeSection.LeadingComments) LeadingComments.Add(comment); Keys.Merge(toMergeSection.Keys); foreach(var comment in toMergeSection.TrailingComments) TrailingComments.Add(comment); }
/// <summary> /// Merge the sections into this by overwriting this sections. /// </summary> private void MergeSection(SectionData otherSection) { // no overlap -> create no section if (!Sections.ContainsSection(otherSection.SectionName)) { Sections.AddSection(otherSection.SectionName); } // merge section into the new one Sections.GetSectionData(otherSection.SectionName).Merge(otherSection); }