/* Copyright 2007-2013 The NGenerics Team (https://github.com/ngenerics/ngenerics/wiki/Team) This program is licensed under the GNU Lesser General Public License (LGPL). You should have received a copy of the license along with the source code. If not, an online copy of the license can be found at http://www.gnu.org/copyleft/lesser.html. */ using System; using System.Collections.Generic; using NGenerics.Util; namespace NGenerics.Comparers { /// /// A comparer that wraps the IComparable interface to reproduce the opposite comparison result. /// /// The type of the objects to compare. //[Serializable] public sealed class ReverseComparer : IComparer { #region Globals private IComparer comparerToUse; #endregion #region Construction /// public ReverseComparer() { comparerToUse = Comparer.Default; } /// The comparer to reverse. /// is a null reference (Nothing in Visual Basic). public ReverseComparer(IComparer comparer) { Guard.ArgumentNotNull(comparer, "comparer"); comparerToUse = comparer; } #endregion #region IComparer Members /// public int Compare(T x, T y) { return (comparerToUse.Compare(y, x)); } #endregion #region Public Members /// /// Gets or sets the comparer used in this instance. /// /// The comparer. /// is a null reference (Nothing in Visual Basic). public IComparer Comparer { get { return comparerToUse; } set { Guard.ArgumentNotNull(value, "value"); comparerToUse = value; } } #endregion } }