#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2009 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
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(ComparedType left, ComparedType right) {
return this.comparer.Compare(right, left); // intentionally reversed
}
/// The default comparer from the .NET framework
private IComparer comparer;
}
} // namespace Nuclex.Support.Collections