5 changed files with 33 additions and 5 deletions
@ -0,0 +1,30 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace Elastic.Clients.Elasticsearch; |
||||
|
|
||||
|
public static class SortOptionsExtenssions |
||||
|
{ |
||||
|
public static IEnumerable<SortOptions>? ReverseSort(this IEnumerable<SortOptions>? sortOptions) |
||||
|
{ |
||||
|
if (sortOptions == null) |
||||
|
{ |
||||
|
return sortOptions; |
||||
|
} |
||||
|
var newSort = sortOptions.Select(sort => |
||||
|
{ |
||||
|
if (sort.Field != null) |
||||
|
{ |
||||
|
sort.Field.Order = sort.Field.Order == SortOrder.Asc |
||||
|
? SortOrder.Desc |
||||
|
: SortOrder.Asc; |
||||
|
} |
||||
|
return sort; |
||||
|
}).ToArray(); |
||||
|
|
||||
|
newSort.Reverse(); |
||||
|
|
||||
|
return newSort; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue