Last active
June 4, 2019 16:14
-
-
Save searope/47da119afb0a8948ada97ff2aefcedf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| public class SortComparer<T, R> : Comparer<T> where R : IComparable<R> | |
| { | |
| public readonly Func<T, R> GetComparableProperty; | |
| private SortComparer(){} | |
| private SortComparer(Func<T, R> func) | |
| { | |
| GetComparableProperty = func; | |
| } | |
| public static IComparer<T> Create(Func<T, R> func) | |
| { | |
| return new SortComparer<T, R>(func); | |
| } | |
| public override int Compare(T x, T y) | |
| { | |
| return GetComparableProperty(x).CompareTo(GetComparableProperty(y)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment