internal static void HandleDuplicateSections(Sentence firstSentence, DuplicateSectionHandling duplicateSectionHandling) { if (duplicateSectionHandling == DuplicateSectionHandling.Allow) { return; } var duplicateSectionsGroups = firstSentence.DuplicateSectionGroups(); if (!duplicateSectionsGroups.Any()) { return; } if (duplicateSectionHandling == DuplicateSectionHandling.Disallow) { throw new DuplicateSectionsException(); } if (duplicateSectionHandling == DuplicateSectionHandling.Merge) { foreach (var duplicateSecionGroup in duplicateSectionsGroups) { var baseSection = duplicateSecionGroup.First(); var mergeSections = duplicateSecionGroup.Skip(1); foreach (var mergeSection in mergeSections) { var properties = mergeSection.Properties().ToList(); foreach (var property in properties) { var lastBaseSectionProperty = baseSection.Properties().Last(); lastBaseSectionProperty.Next = property; } mergeSection.Remove(); } } } }