| | 1 | | using System.Diagnostics; |
| | 2 | |
|
| | 3 | | namespace Pozitron.QuerySpecification; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// Represents a like expression used in a specification. |
| | 7 | | /// </summary> |
| | 8 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 9 | | public sealed class LikeExpression<T> |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Gets the key selector expression. |
| | 13 | | /// </summary> |
| 3 | 14 | | public Expression<Func<T, string?>> KeySelector { get; } |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Gets the pattern to match. |
| | 18 | | /// </summary> |
| 3 | 19 | | public string Pattern { get; } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Gets the group number. |
| | 23 | | /// </summary> |
| 11 | 24 | | public int Group { get; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Initializes a new instance of the <see cref="LikeExpression{T}"/> class. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="keySelector">The key selector expression.</param> |
| | 30 | | /// <param name="pattern">The pattern to match.</param> |
| | 31 | | /// <param name="group">The group number.</param> |
| 31 | 32 | | public LikeExpression(Expression<Func<T, string?>> keySelector, string pattern, int group = 1) |
| | 33 | | { |
| | 34 | | Debug.Assert(keySelector is not null); |
| | 35 | | Debug.Assert(!string.IsNullOrEmpty(pattern)); |
| 31 | 36 | | KeySelector = keySelector; |
| 31 | 37 | | Pattern = pattern; |
| 31 | 38 | | Group = group; |
| 31 | 39 | | } |
| | 40 | | } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Represents a compiled like expression used in a specification. |
| | 44 | | /// </summary> |
| | 45 | | /// <typeparam name="T">The type of the entity.</typeparam> |
| | 46 | | public sealed class LikeExpressionCompiled<T> |
| | 47 | | { |
| | 48 | | /// <summary> |
| | 49 | | /// Gets the compiled key selector function. |
| | 50 | | /// </summary> |
| | 51 | | public Func<T, string?> KeySelector { get; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Gets the pattern to match. |
| | 55 | | /// </summary> |
| | 56 | | public string Pattern { get; } |
| | 57 | |
|
| | 58 | | /// <summary> |
| | 59 | | /// Gets the group number. |
| | 60 | | /// </summary> |
| | 61 | | public int Group { get; } |
| | 62 | |
|
| | 63 | | /// <summary> |
| | 64 | | /// Initializes a new instance of the <see cref="LikeExpressionCompiled{T}"/> class. |
| | 65 | | /// </summary> |
| | 66 | | /// <param name="keySelector">The compiled key selector function.</param> |
| | 67 | | /// <param name="pattern">The pattern to match.</param> |
| | 68 | | /// <param name="group">The group number.</param> |
| | 69 | | public LikeExpressionCompiled(Func<T, string?> keySelector, string pattern, int group = 1) |
| | 70 | | { |
| | 71 | | Debug.Assert(keySelector is not null); |
| | 72 | | Debug.Assert(!string.IsNullOrEmpty(pattern)); |
| | 73 | | KeySelector = keySelector; |
| | 74 | | Pattern = pattern; |
| | 75 | | Group = group; |
| | 76 | | } |
| | 77 | | } |