Example #1
0
        public void Sort(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.Length - index >= length), "Check the arguments in the caller!");

            // Add a try block here to detect IComparers (or their
            // underlying IComparables, etc) that are bogus.
            try
            {
                if (comparer == null)
                {
                    comparer = Comparer <T> .Default;
                }

                IntrospectiveSort(keys, index, length, comparer.Compare);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
            }
        }
Example #2
0
 // Token: 0x06003A38 RID: 14904 RVA: 0x000DCD3C File Offset: 0x000DAF3C
 public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer <TKey> comparer)
 {
     try
     {
         if (comparer == null || comparer == Comparer <TKey> .Default)
         {
             comparer = Comparer <TKey> .Default;
         }
         if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
         {
             ArraySortHelper <TKey, TValue> .IntrospectiveSort(keys, values, index, length, comparer);
         }
         else
         {
             ArraySortHelper <TKey, TValue> .DepthLimitedQuickSort(keys, values, index, length + index - 1, comparer, 32);
         }
     }
     catch (IndexOutOfRangeException)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
     }
     catch (Exception innerException)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), innerException);
     }
 }
Example #3
0
        // Do not add a constructor to this class because ArraySortHelper<T>.CreateSortHelper will not execute it

        #region IArraySortHelper<T> Members

        public void Sort(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.Length - index >= length), "Check the arguments in the caller!");

            try
            {
                if (comparer == null || comparer == Comparer <T> .Default)
                {
                    IntrospectiveSort(keys, index, length);
                }
                else
                {
                    ArraySortHelper <T> .IntrospectiveSort(keys, index, length, comparer.Compare);
                }
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
            }
        }
Example #4
0
 public void Sort(T[] keys, int index, int length, IComparer <T> comparer)
 {
     try
     {
         if (comparer == null || comparer == Comparer <T> .Default)
         {
             if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
             {
                 GenericArraySortHelper <T> .IntrospectiveSort(keys, index, length);
             }
             else
             {
                 GenericArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, 32);
             }
         }
         else if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
         {
             ArraySortHelper <T> .IntrospectiveSort(keys, index, length, comparer);
         }
         else
         {
             ArraySortHelper <T> .DepthLimitedQuickSort(keys, index, length + index - 1, comparer, 32);
         }
     }
     catch (IndexOutOfRangeException ex)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer((object)comparer);
     }
     catch (Exception ex)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), ex);
     }
 }
Example #5
0
        internal static void Sort(Span <T> keys, Comparison <T> comparer)
        {
            Debug.Assert(comparer != null, "Check the arguments in the caller!");

            // Add a try block here to detect bogus comparisons
            try
            {
                IntrospectiveSort(keys, comparer);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
            }
        }
Example #6
0
 public void Sort(Span <T> keys, IComparer <T>?comparer)
 {
     // Add a try block here to detect IComparers (or their
     // underlying IComparables, etc) that are bogus.
     try
     {
         comparer ??= Comparer <T> .Default;
         IntrospectiveSort(keys, comparer.Compare);
     }
     catch (IndexOutOfRangeException)
     {
         IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
     }
     catch (Exception e)
     {
         throw new InvalidOperationException(SR.InvalidOperation_IComparerFailed, e);
     }
 }
        internal static void Sort(IList <T> keys, int index, int length, Comparison <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!");
            Debug.Assert(comparer != null, "Check the arguments in the caller!");

            // Add a try block here to detect bogus comparisons
            try
            {
                IntrospectiveSort(keys, index, length, comparer);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Resource.InvalidOperation_IComparerFailed, e);
            }
        }
Example #8
0
        internal static void Sort(T[] keys, int index, int length, Comparison <T> comparer)
        {
            Contract.Assert(keys != null, "Check the arguments in the caller!");
            Contract.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
            Contract.Assert(comparer != null, "Check the arguments in the caller!");

            // Add a try block here to detect bogus comparisons
            try
            {
                IntrospectiveSort(keys, index, length, comparer);
            }
            catch (IndexOutOfRangeException)
            {
                IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer(comparer);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_IComparerFailed"), e);
            }
        }