// Do not add a constructor to this class because ListSortHelper<T>.CreateSortHelper will not execute it

        #region IListSortHelper<T> Members

        public void Sort(IList <T> keys, int index, int length, IComparer <T> comparer)
        {
            Debug.Assert(keys != null, "Check the arguments in the caller!");
            Debug.Assert(index >= 0 && length >= 0 && (keys.Count - index >= length), "Check the arguments in the caller!");

            try
            {
                if (comparer == null || comparer == Comparer <T> .Default)
                {
                    IntrospectiveSort(keys, index, length);
                }
                else
                {
                    ListSortHelper <T> .IntrospectiveSort(keys, index, length, comparer.Compare);
                }
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Resource.InvalidOperation_IComparerFailed, e);
            }
        }
        public int BinarySearch(IList <T> list, int index, int length, T value, IComparer <T> comparer)
        {
            Debug.Assert(list != null, "Check the arguments in the caller!");
            Debug.Assert(index >= 0 && length >= 0 && (list.Count - index >= length), "Check the arguments in the caller!");

            try
            {
                if (comparer == null || comparer == Comparer <T> .Default)
                {
                    return(BinarySearch(list, index, length, value));
                }
                else
                {
                    return(ListSortHelper <T> .InternalBinarySearch(list, index, length, value, comparer));
                }
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Resource.InvalidOperation_IComparerFailed, e);
            }
        }