// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System.Collections.Generic; using UnityEngine; namespace Microsoft.MixedReality.Toolkit { /// /// Extension methods for .Net Comparer's /// public static class ComparerExtensions { /// /// Gets a comparer that sorts elements in the opposite order of the original comparer. /// /// The type of element the comparer compares. /// The comparer whose order should be reversed. /// A comparer that sorts elements in the opposite order of . public static IComparer GetReversed(this IComparer originalComparer) { return new ReverseComparer(originalComparer); } private class ReverseComparer : IComparer { private readonly IComparer originalComparer; public ReverseComparer(IComparer originalComparer) { Debug.Assert(originalComparer != null, "originalComparer cannot be null."); this.originalComparer = originalComparer; } public int Compare(TElement left, TElement right) { return originalComparer.Compare(right, left); } } } }