#region Apache License 2.0
/*
Nuclex .NET Framework
Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#endregion // Apache License 2.0
using System;
using System.Collections.Generic;
namespace Nuclex.Support.Collections {
///
/// Compares two values in reverse or reverses the output of another comparer
///
/// Type of values to be compared
public class ReverseComparer : IComparer {
/// Initializes a new reverse comparer
public ReverseComparer() : this(Comparer.Default) { }
///
/// Initializes the comparer to provide the inverse results of another comparer
///
/// Comparer whose results will be inversed
public ReverseComparer(IComparer comparerToReverse) {
this.comparer = comparerToReverse;
}
/// Compares the left value to the right value
/// Value on the left side
/// Value on the right side
/// The relationship of the two values
public int Compare(TCompared left, TCompared right) {
return this.comparer.Compare(right, left); // intentionally reversed
}
/// The default comparer from the .NET framework
private IComparer comparer;
}
} // namespace Nuclex.Support.Collections