Added read-only collection wrappers for IDictionary<>, IList<> and ICollection<> since the classes provided by the .NET framework in System.Collections.ObjectModel are incomplete and inconsistent (eg. System.Collections.ObjectModel.ReadOnlyCollection wraps an IList<>!); minor improvements to documentation; added ReverseComparer for inverting the results of an existing IComparer<> or simply comparing values in inverted order
git-svn-id: file:///srv/devel/repo-conversion/nusu@80 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
f5eefc6765
commit
2cc7b27b0c
7 changed files with 748 additions and 16 deletions
36
Source/Collections/ReverseComparer.cs
Normal file
36
Source/Collections/ReverseComparer.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Nuclex.Support.Collections {
|
||||
|
||||
/// <summary>
|
||||
/// Compares two values in reverse or reverses the output of another comparer
|
||||
/// </summary>
|
||||
/// <typeparam name="ComparedType">Type of values to be compared</typeparam>
|
||||
public class ReverseComparer<ComparedType> : IComparer<ComparedType> {
|
||||
|
||||
/// <summary>Initializes a new reverse comparer</summary>
|
||||
public ReverseComparer() : this(Comparer<ComparedType>.Default) { }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the comparer to provide the inverse results of another comparer
|
||||
/// </summary>
|
||||
/// <param name="comparerToReverse">Comparer whose results will be inversed</param>
|
||||
public ReverseComparer(IComparer<ComparedType> comparerToReverse) {
|
||||
this.comparer = comparerToReverse;
|
||||
}
|
||||
|
||||
/// <summary>Compares the left value to the right value</summary>
|
||||
/// <param name="left">Value on the left side</param>
|
||||
/// <param name="right">Value on the right side</param>
|
||||
/// <returns>The relationship of the two values</returns>
|
||||
public int Compare(ComparedType left, ComparedType right) {
|
||||
return this.comparer.Compare(right, left); // intentionally reversed
|
||||
}
|
||||
|
||||
/// <summary>The default comparer from the .NET framework</summary>
|
||||
private IComparer<ComparedType> comparer;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Nuclex.Support.Collections
|
||||
Loading…
Add table
Add a link
Reference in a new issue