mirror of
https://github.com/Biarity/Sieve.git
synced 2025-10-22 05:15:30 +02:00
Base & test solution
This commit is contained in:
31
Sieve/Extensions/OrderByWithDirection.cs
Normal file
31
Sieve/Extensions/OrderByWithDirection.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace Sieve.Extensions
|
||||
{
|
||||
|
||||
public static class LinqExtensions
|
||||
{
|
||||
public static IOrderedEnumerable<TSource> OrderByWithDirection<TSource, TKey>
|
||||
(this IEnumerable<TSource> source,
|
||||
Func<TSource, TKey> keySelector,
|
||||
bool descending)
|
||||
{
|
||||
return descending ? source.OrderByDescending(keySelector)
|
||||
: source.OrderBy(keySelector);
|
||||
}
|
||||
|
||||
public static IOrderedQueryable<TSource> OrderByWithDirection<TSource, TKey>
|
||||
(this IQueryable<TSource> source,
|
||||
Expression<Func<TSource, TKey>> keySelector,
|
||||
bool descending)
|
||||
{
|
||||
return descending ? source.OrderByDescending(keySelector)
|
||||
: source.OrderBy(keySelector);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user