https://github.com/devizer/universe.yetanothercomparerbuilder
Emit-free, fast, strongly typed, highly-customizable yet another ComparerBuilder
https://github.com/devizer/universe.yetanothercomparerbuilder
Last synced: 3 months ago
JSON representation
Emit-free, fast, strongly typed, highly-customizable yet another ComparerBuilder
- Host: GitHub
- URL: https://github.com/devizer/universe.yetanothercomparerbuilder
- Owner: devizer
- License: mit
- Created: 2017-12-18T16:12:21.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-21T12:58:45.000Z (about 6 years ago)
- Last Synced: 2025-10-09T19:03:10.769Z (4 months ago)
- Language: C#
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Universe.YetAnotherComparerBuilder
Emit-free, fast, strongly typed, highly-customizable yet another ComparerBuilder

## The icing on the
Extended order direction can be applyed to both an element comparer and a field comparer:
```csharp
[Flags]
public enum OrderFlavour
{
Forward = 0,
Backward = 1,
NullGoesFinally = 0,
NullGoesEarly = 2,
Default = Forward | NullGoesFinally,
}
```
# Sample
In this sample all Doctors aged 42 will ahead of another persons.
```csharp
public class Demo
{
class Person
{
public string Title;
public string Name;
public int? Age;
}
public static void Test()
{
StringComparer ignoreCase = StringComparer.InvariantCultureIgnoreCase;
string highlightTitle = "Dr.";
int highlightAge = 42;
IComparer comparer = new ComparerBuilder()
.Compare(x => ignoreCase.Equals(highlightTitle, x.Title))
.Compare(x => x.Age.HasValue && highlightAge == x.Age.Value)
.CompareString(x => x.Name, ignoreCase)
.CompareString(x => x.Title, ignoreCase)
.Compare(x => x.Age, OrderFlavour.Backward | OrderFlavour.NullGoesFinally)
.GetComparer();
Enumerable.Empty().ToList().Sort(comparer);
Enumerable.Empty().OrderBy(x => x, comparer).ToList();
}
}
```