Ejemplo n.º 1
0
        /// <summary>
        /// Reorders an array of pages to the correct order for searching through
        /// </summary>
        /// <param Name="pages">The array of pages to search</param>
        /// <param Name="startPage">The page to start on. Null indicates all pages should be searched</param>
        /// <param Name="reverse">The direction the search should happen in</param>
        /// <returns>The reorded array</returns>
        protected static Page[] OrderPages(Page[] pages, int? startPage, bool reverse)
        {
            //If it needs to scan everything, make sure it starts in the right place
            if (startPage == null)
            {
                if (!reverse) { startPage = 0; }
                else { startPage = pages.Length - 1; }
            }

            //If the search is forwards, take only the start page and following pages
            if (!reverse) { return pages.Skip((int)startPage).ToArray(); }

            //If the search is backwards, take only the start page and preceding pages, then reverse the order
            else { return pages.Take((int)startPage + 1).Reverse().ToArray(); }
        }