/** * <summary>Moves a page range to a target position within the document.</summary> * <param name="startIndex">The beginning index, inclusive.</param> * <param name="endIndex">The ending index, exclusive.</param> * <param name="targetIndex">The target index.</param> */ public void Move( int startIndex, int endIndex, int targetIndex ) { int pageCount = pages.Count; IList <Page> movingPages = pages.GetSlice(startIndex, endIndex); // Temporarily remove the pages from the pages collection! /* * NOTE: Shallow removal (only page references are removed, as their data are kept in the document). */ pages.RemoveAll(movingPages); // Adjust indexes! pageCount -= movingPages.Count; if (targetIndex > startIndex) { targetIndex -= movingPages.Count; } // Adjusts the target position due to shifting for temporary page removal. // Reinsert the pages at the target position! /* * NOTE: Shallow addition (only page references are added, as their data are already in the document). */ if (targetIndex >= pageCount) { pages.AddAll(movingPages); } else { pages.InsertAll(targetIndex, movingPages); } pages.Update(); // NOTE: Update is fundamental to override original page collection. }