| | | 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 && !Specification<T, TResult>.IsChainDiscarded) |
| | | 16 | | { |
| | 5 | 17 | | orderedBuilder.Specification.AddInternal(ItemType.Order, orderExpression, (int)OrderType.ThenBy); |
| | | 18 | | } |
| | | 19 | | else |
| | | 20 | | { |
| | 4 | 21 | | Specification<T, TResult>.IsChainDiscarded = true; |
| | | 22 | | } |
| | | 23 | | |
| | 9 | 24 | | return orderedBuilder; |
| | | 25 | | } |
| | | 26 | | |
| | | 27 | | public static IOrderedSpecificationBuilder<T> ThenBy<T>( |
| | | 28 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | | 29 | | Expression<Func<T, object?>> orderExpression) |
| | 13 | 30 | | => ThenBy(orderedBuilder, orderExpression, true); |
| | | 31 | | |
| | | 32 | | public static IOrderedSpecificationBuilder<T> ThenBy<T>( |
| | | 33 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | | 34 | | Expression<Func<T, object?>> orderExpression, |
| | | 35 | | bool condition) |
| | | 36 | | { |
| | 15 | 37 | | if (condition && !Specification<T>.IsChainDiscarded) |
| | | 38 | | { |
| | 11 | 39 | | orderedBuilder.Specification.AddInternal(ItemType.Order, orderExpression, (int)OrderType.ThenBy); |
| | | 40 | | } |
| | | 41 | | else |
| | | 42 | | { |
| | 4 | 43 | | Specification<T>.IsChainDiscarded = true; |
| | | 44 | | } |
| | | 45 | | |
| | 15 | 46 | | return orderedBuilder; |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | public static IOrderedSpecificationBuilder<T, TResult> ThenByDescending<T, TResult>( |
| | | 50 | | this IOrderedSpecificationBuilder<T, TResult> orderedBuilder, |
| | | 51 | | Expression<Func<T, object?>> orderExpression) |
| | 11 | 52 | | => ThenByDescending(orderedBuilder, orderExpression, true); |
| | | 53 | | |
| | | 54 | | public static IOrderedSpecificationBuilder<T, TResult> ThenByDescending<T, TResult>( |
| | | 55 | | this IOrderedSpecificationBuilder<T, TResult> orderedBuilder, |
| | | 56 | | Expression<Func<T, object?>> orderExpression, |
| | | 57 | | bool condition) |
| | | 58 | | { |
| | 13 | 59 | | if (condition && !Specification<T, TResult>.IsChainDiscarded) |
| | | 60 | | { |
| | 9 | 61 | | orderedBuilder.Specification.AddInternal(ItemType.Order, orderExpression, (int)OrderType.ThenByDescending); |
| | | 62 | | } |
| | | 63 | | else |
| | | 64 | | { |
| | 4 | 65 | | Specification<T, TResult>.IsChainDiscarded = true; |
| | | 66 | | } |
| | | 67 | | |
| | 13 | 68 | | return orderedBuilder; |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | public static IOrderedSpecificationBuilder<T> ThenByDescending<T>( |
| | | 72 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | | 73 | | Expression<Func<T, object?>> orderExpression) |
| | 13 | 74 | | => ThenByDescending(orderedBuilder, orderExpression, true); |
| | | 75 | | |
| | | 76 | | public static IOrderedSpecificationBuilder<T> ThenByDescending<T>( |
| | | 77 | | this IOrderedSpecificationBuilder<T> orderedBuilder, |
| | | 78 | | Expression<Func<T, object?>> orderExpression, |
| | | 79 | | bool condition) |
| | | 80 | | { |
| | 15 | 81 | | if (condition && !Specification<T>.IsChainDiscarded) |
| | | 82 | | { |
| | 11 | 83 | | orderedBuilder.Specification.AddInternal(ItemType.Order, orderExpression, (int)OrderType.ThenByDescending); |
| | | 84 | | } |
| | | 85 | | else |
| | | 86 | | { |
| | 4 | 87 | | Specification<T>.IsChainDiscarded = true; |
| | | 88 | | } |
| | | 89 | | |
| | 15 | 90 | | return orderedBuilder; |
| | | 91 | | } |
| | | 92 | | } |