| | 1 | | namespace Pozitron.QuerySpecification; |
| | 2 | |
|
| | 3 | | public static class OrderedBuilderExtensions |
| | 4 | | { |
| | 5 | | public static IOrderedSpecificationBuilder<T, TResult> ThenBy<T, TResult>( |
| | 6 | | this IOrderedSpecificationBuilder<T, TResult> orderedBuilder, |
| | 7 | | Expression<Func<T, object?>> orderExpression) |
| 7 | 8 | | => ThenBy(orderedBuilder, orderExpression, true); |
| | 9 | |
|
| | 10 | | public static IOrderedSpecificationBuilder<T, TResult> ThenBy<T, TResult>( |
| | 11 | | this IOrderedSpecificationBuilder<T, TResult> orderedBuilder, |
| | 12 | | Expression<Func<T, object?>> orderExpression, |
| | 13 | | bool condition) |
| | 14 | | { |
| 9 | 15 | | if (condition && !orderedBuilder.IsChainDiscarded) |
| | 16 | | { |
| 5 | 17 | | var expr = new OrderExpression<T>(orderExpression, OrderTypeEnum.ThenBy); |
| 5 | 18 | | orderedBuilder.Specification.Add(expr); |
| | 19 | | } |
| | 20 | | else |
| | 21 | | { |
| 4 | 22 | | orderedBuilder.IsChainDiscarded = true; |
| | 23 | | } |
| | 24 | |
|
| 9 | 25 | | return orderedBuilder; |
| | 26 | | } |
| | 27 | |
|
| | 28 | | public static IOrderedSpecificationBuilder<T> ThenBy<T>( |
| | 29 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | 30 | | Expression<Func<T, object?>> orderExpression) |
| 9 | 31 | | => ThenBy(orderedBuilder, orderExpression, true); |
| | 32 | |
|
| | 33 | | public static IOrderedSpecificationBuilder<T> ThenBy<T>( |
| | 34 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | 35 | | Expression<Func<T, object?>> orderExpression, |
| | 36 | | bool condition) |
| | 37 | | { |
| 11 | 38 | | if (condition && !orderedBuilder.IsChainDiscarded) |
| | 39 | | { |
| 7 | 40 | | var expr = new OrderExpression<T>(orderExpression, OrderTypeEnum.ThenBy); |
| 7 | 41 | | orderedBuilder.Specification.Add(expr); |
| | 42 | | } |
| | 43 | | else |
| | 44 | | { |
| 4 | 45 | | orderedBuilder.IsChainDiscarded = true; |
| | 46 | | } |
| | 47 | |
|
| 11 | 48 | | return orderedBuilder; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public static IOrderedSpecificationBuilder<T, TResult> ThenByDescending<T, TResult>( |
| | 52 | | this IOrderedSpecificationBuilder<T, TResult> orderedBuilder, |
| | 53 | | Expression<Func<T, object?>> orderExpression) |
| 11 | 54 | | => ThenByDescending(orderedBuilder, orderExpression, true); |
| | 55 | |
|
| | 56 | | public static IOrderedSpecificationBuilder<T, TResult> ThenByDescending<T, TResult>( |
| | 57 | | this IOrderedSpecificationBuilder<T, TResult> orderedBuilder, |
| | 58 | | Expression<Func<T, object?>> orderExpression, |
| | 59 | | bool condition) |
| | 60 | | { |
| 13 | 61 | | if (condition && !orderedBuilder.IsChainDiscarded) |
| | 62 | | { |
| 9 | 63 | | var expr = new OrderExpression<T>(orderExpression, OrderTypeEnum.ThenByDescending); |
| 9 | 64 | | orderedBuilder.Specification.Add(expr); |
| | 65 | | } |
| | 66 | | else |
| | 67 | | { |
| 4 | 68 | | orderedBuilder.IsChainDiscarded = true; |
| | 69 | | } |
| | 70 | |
|
| 13 | 71 | | return orderedBuilder; |
| | 72 | | } |
| | 73 | |
|
| | 74 | | public static IOrderedSpecificationBuilder<T> ThenByDescending<T>( |
| | 75 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | 76 | | Expression<Func<T, object?>> orderExpression) |
| 13 | 77 | | => ThenByDescending(orderedBuilder, orderExpression, true); |
| | 78 | |
|
| | 79 | | public static IOrderedSpecificationBuilder<T> ThenByDescending<T>( |
| | 80 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | 81 | | Expression<Func<T, object?>> orderExpression, |
| | 82 | | bool condition) |
| | 83 | | { |
| 15 | 84 | | if (condition && !orderedBuilder.IsChainDiscarded) |
| | 85 | | { |
| 11 | 86 | | var expr = new OrderExpression<T>(orderExpression, OrderTypeEnum.ThenByDescending); |
| 11 | 87 | | orderedBuilder.Specification.Add(expr); |
| | 88 | | } |
| | 89 | | else |
| | 90 | | { |
| 4 | 91 | | orderedBuilder.IsChainDiscarded = true; |
| | 92 | | } |
| | 93 | |
|
| 15 | 94 | | return orderedBuilder; |
| | 95 | | } |
| | 96 | | } |