/* 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; namespace NGenerics.Comparers { /// /// A comparer for comparing keys for the KeyValuePair class. /// /// The key type. /// The value type. //[Serializable] public class KeyValuePairComparer : IComparer> { #region Globals private readonly IComparer comparer; #endregion #region Construction /// /// Initializes a new instance of the class. /// public KeyValuePairComparer() { comparer = Comparer.Default; } /// /// Initializes a new instance of the class. /// /// The comparer. public KeyValuePairComparer(IComparer comparer) { if (comparer == null) { throw new ArgumentNullException("comparer"); } this.comparer = comparer; } /// /// Initializes a new instance of the class. /// /// The comparison. public KeyValuePairComparer(Comparison comparison) { if (comparison == null) { throw new ArgumentNullException("comparison"); } comparer = new ComparisonComparer(comparison); } #endregion #region IComparer> Members /// public int Compare(KeyValuePair x, KeyValuePair y) { return comparer.Compare(x.Key, y.Key); } #endregion #region IComparer Members /// public int Compare(TKey x, TKey y) { return comparer.Compare(x, y); } #endregion } }