| | 1 | | using Fluorite.Strainer.Models.Sorting; |
| | 2 | | using Fluorite.Strainer.Models.Sorting.Terms; |
| | 3 | | using System.Linq.Expressions; |
| | 4 | |
|
| | 5 | | namespace Fluorite.Strainer.Services.Sorting; |
| | 6 | |
|
| | 7 | | public class CustomSortMethodBuilderWithExpression<TEntity> : CustomSortMethodBuilderWithName<TEntity>, ICustomSortMetho |
| | 8 | | { |
| | 9 | | public CustomSortMethodBuilderWithExpression( |
| | 10 | | string name, Expression<Func<TEntity, object>> expression) |
| 5 | 11 | | : base(name) |
| | 12 | | { |
| 5 | 13 | | Expression = Guard.Against.Null(expression); |
| 5 | 14 | | } |
| | 15 | |
|
| | 16 | | public CustomSortMethodBuilderWithExpression( |
| | 17 | | string name, |
| | 18 | | Func<ISortTerm, Expression<Func<TEntity, object>>> sortTermExpression) |
| 1 | 19 | | : base(name) |
| | 20 | | { |
| 1 | 21 | | SortTermExpression = Guard.Against.Null(sortTermExpression); |
| 1 | 22 | | } |
| | 23 | |
|
| 4 | 24 | | public Expression<Func<TEntity, object>>? Expression { get; } |
| | 25 | |
|
| 6 | 26 | | public Func<ISortTerm, Expression<Func<TEntity, object>>>? SortTermExpression { get; } |
| | 27 | |
|
| | 28 | | public ICustomSortMethod<TEntity> Build() |
| | 29 | | { |
| 5 | 30 | | if (SortTermExpression is null) |
| | 31 | | { |
| 4 | 32 | | return new CustomSortMethod<TEntity>(Name, Expression!); |
| | 33 | | } |
| | 34 | | else |
| | 35 | | { |
| 1 | 36 | | return new CustomSortMethod<TEntity>(Name, SortTermExpression); |
| | 37 | | } |
| | 38 | | } |
| | 39 | | } |