| | 1 | | using System.Diagnostics; |
| | 2 | | using System.Linq.Expressions; |
| | 3 | |
|
| | 4 | | namespace Fluorite.Strainer.Models.Filtering.Operators; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Provides information about filtering operator. |
| | 8 | | /// </summary> |
| | 9 | | [DebuggerDisplay("\\{{" + nameof(Symbol) + ",nq} {" + nameof(Name) + ",nq}\\}")] |
| | 10 | | public class FilterOperator : IFilterOperator |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Initializes a new instance of the <see cref="FilterOperator"/> class. |
| | 14 | | /// </summary> |
| 26 | 15 | | public FilterOperator(string name, string symbol, Func<IFilterExpressionContext, Expression> expressionFunc) |
| | 16 | | { |
| 26 | 17 | | Name = Guard.Against.NullOrWhiteSpace(name); |
| 26 | 18 | | Symbol = Guard.Against.NullOrWhiteSpace(symbol); |
| 26 | 19 | | ExpressionProvider = Guard.Against.Null(expressionFunc); |
| 26 | 20 | | } |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Gets a func providing an <see cref="Expression"/> |
| | 24 | | /// with filter operator applied when supplied a <see cref="IFilterExpressionContext"/>. |
| | 25 | | /// </summary> |
| 484 | 26 | | public Func<IFilterExpressionContext, Expression> ExpressionProvider { get; } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Gets or sets a value indicating whether current |
| | 30 | | /// operator is case insensitive. |
| | 31 | | /// </summary> |
| 26 | 32 | | public bool IsCaseInsensitive { get; set; } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Gets or sets a value indicating whether associated |
| | 36 | | /// <see cref="Expression"/> uses method |
| | 37 | | /// based on a <see cref="string"/> instance like |
| | 38 | | /// <see cref="string.Contains(string)"/> or <see cref="string.StartsWith(string)"/>. |
| | 39 | | /// </summary> |
| 26 | 40 | | public bool IsStringBased { get; set; } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Gets the operator name. |
| | 44 | | /// </summary> |
| 3 | 45 | | public string Name { get; } |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Gets a <see cref="string"/> representation of the operator. |
| | 49 | | /// </summary> |
| 524 | 50 | | public string Symbol { get; } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Returns a <see cref="string"/> that represents the current <see cref="FilterOperator"/>. |
| | 54 | | /// </summary> |
| | 55 | | /// <returns> |
| | 56 | | /// A <see cref="string"/> that represents the current <see cref="FilterOperator"/>. |
| | 57 | | /// </returns> |
| | 58 | | public override string ToString() |
| | 59 | | { |
| 0 | 60 | | return $"{Symbol} {Name}"; |
| | 61 | | } |
| | 62 | | } |