| | 1 | | using Fluorite.Strainer.Models.Sorting.Terms; |
| | 2 | | using System.Linq.Expressions; |
| | 3 | |
|
| | 4 | | namespace Fluorite.Strainer.Models.Sorting; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Represents custom sort method. |
| | 8 | | /// </summary> |
| | 9 | | /// <typeparam name="T"> |
| | 10 | | /// The type of entity processed by the custom method. |
| | 11 | | /// </typeparam> |
| | 12 | | public class CustomSortMethod<T> : CustomSortMethod, ICustomSortMethod<T> |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Initializes a new instance of the <see cref="CustomSortMethod{T}"/> class. |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="name"> |
| | 18 | | /// The custom sort method name. |
| | 19 | | /// </param> |
| | 20 | | /// <param name="expression"> |
| | 21 | | /// The expression used for custom sorting. |
| | 22 | | /// </param> |
| 4 | 23 | | public CustomSortMethod(string name, Expression<Func<T, object>> expression) : base(name) |
| | 24 | | { |
| 4 | 25 | | Expression = Guard.Against.Null(expression); |
| 4 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Initializes a new instance of the <see cref="CustomSortMethod{T}"/> class. |
| | 30 | | /// </summary> |
| | 31 | | /// <param name="name"> |
| | 32 | | /// The custom sort method name. |
| | 33 | | /// </param> |
| | 34 | | /// <param name="expressionProvider"> |
| | 35 | | /// The expression used for custom sorting. |
| | 36 | | /// </param> |
| 1 | 37 | | public CustomSortMethod(string name, Func<ISortTerm, Expression<Func<T, object>>> expressionProvider) : base(name) |
| | 38 | | { |
| 1 | 39 | | ExpressionProvider = Guard.Against.Null(expressionProvider); |
| 1 | 40 | | } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Gets the expression used for custom sorting. |
| | 44 | | /// </summary> |
| 5 | 45 | | public Expression<Func<T, object>>? Expression { get; } |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Gets the provider of expression used for custom sorting. |
| | 49 | | /// </summary> |
| 4 | 50 | | public Func<ISortTerm, Expression<Func<T, object>>>? ExpressionProvider { get; } |
| | 51 | | } |