csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.2 KiB
83 lines
2.2 KiB
/*
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// A comparer that wraps the IComparable interface to reproduce the opposite comparison result.
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of the objects to compare.</typeparam>
|
|
//[Serializable]
|
|
public sealed class ReverseComparer<T> : IComparer<T>
|
|
{
|
|
#region Globals
|
|
|
|
private IComparer<T> comparerToUse;
|
|
|
|
#endregion
|
|
|
|
#region Construction
|
|
/// <inheritdoc />
|
|
public ReverseComparer()
|
|
{
|
|
comparerToUse = Comparer<T>.Default;
|
|
}
|
|
|
|
|
|
/// <param name="comparer">The comparer to reverse.</param>
|
|
/// <exception cref="ArgumentNullException"><paramref name="comparer"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
|
|
public ReverseComparer(IComparer<T> comparer)
|
|
{
|
|
|
|
Guard.ArgumentNotNull(comparer, "comparer");
|
|
comparerToUse = comparer;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region IComparer<T> Members
|
|
|
|
/// <inheritdoc />
|
|
public int Compare(T x, T y)
|
|
{
|
|
return (comparerToUse.Compare(y, x));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Members
|
|
|
|
/// <summary>
|
|
/// Gets or sets the comparer used in this instance.
|
|
/// </summary>
|
|
/// <value>The comparer.</value>
|
|
/// <exception cref="ArgumentNullException"><paramref name="value"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception>
|
|
public IComparer<T> Comparer
|
|
{
|
|
get
|
|
{
|
|
return comparerToUse;
|
|
}
|
|
set
|
|
{
|
|
|
|
Guard.ArgumentNotNull(value, "value");
|
|
|
|
comparerToUse = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|