| | 1 | | using Plainquire.Filter.Abstractions; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using System.Linq.Expressions; |
| | 6 | |
|
| | 7 | | namespace Plainquire.Filter.ValueFilterExpressions; |
| | 8 | |
|
| | 9 | | /// <inheritdoc cref="IBooleanFilterExpression"/> |
| | 10 | | public class BooleanFilterExpression : DefaultFilterExpression, IBooleanFilterExpression |
| | 11 | | { |
| | 12 | | /// <inheritdoc /> |
| | 13 | | public override ICollection<FilterOperator> SupportedFilterOperators |
| | 14 | | => |
| 1575 | 15 | | [ |
| 1575 | 16 | | FilterOperator.Default, |
| 1575 | 17 | | FilterOperator.EqualCaseSensitive, |
| 1575 | 18 | | FilterOperator.EqualCaseInsensitive, |
| 1575 | 19 | | FilterOperator.NotEqual, |
| 1575 | 20 | | FilterOperator.IsNull, |
| 1575 | 21 | | FilterOperator.NotNull |
| 1575 | 22 | | ]; |
| | 23 | |
|
| | 24 | | /// <inheritdoc /> |
| | 25 | | public override bool CanCreateExpressionFor(Type type) |
| 10840 | 26 | | => type.GetUnderlyingType() == typeof(bool); |
| | 27 | |
|
| | 28 | | /// <inheritdoc /> |
| | 29 | | protected internal override Expression? CreateExpressionForValue<TEntity, TProperty>(Expression<Func<TEntity, TPrope |
| | 30 | | { |
| 1136 | 31 | | if (bool.TryParse(value, out var boolValue)) |
| 816 | 32 | | return CreateBoolExpressionByFilterOperator(propertySelector, filterOperator, boolValue); |
| | 33 | |
|
| 320 | 34 | | var boolSyntax = configuration.BooleanMap.FirstOrDefault(x => x.Key.Equals(value, StringComparison.InvariantCult |
| 320 | 35 | | if (boolSyntax.Key != null) |
| 169 | 36 | | return CreateBoolExpressionByFilterOperator(propertySelector, filterOperator, boolSyntax.Value); |
| | 37 | |
|
| 151 | 38 | | if (configuration.IgnoreParseExceptions) |
| 48 | 39 | | return null; |
| | 40 | |
|
| 103 | 41 | | throw CreateFilterExpressionCreationException("Unable to parse given filter value", propertySelector, filterOper |
| | 42 | | } |
| | 43 | |
|
| | 44 | | private Expression CreateBoolExpressionByFilterOperator<TEntity, TProperty>(Expression<Func<TEntity, TProperty>> pro |
| | 45 | | { |
| | 46 | | switch (filterOperator) |
| | 47 | | { |
| | 48 | | case FilterOperator.Default: |
| | 49 | | case FilterOperator.EqualCaseSensitive: |
| | 50 | | case FilterOperator.EqualCaseInsensitive: |
| 793 | 51 | | return CreateEqualExpression(propertySelector, value); |
| | 52 | | case FilterOperator.NotEqual: |
| 192 | 53 | | return CreateNotEqualExpression(propertySelector, value); |
| | 54 | | default: |
| 0 | 55 | | throw CreateFilterExpressionCreationException($"Filter operator '{filterOperator}' not allowed for prope |
| | 56 | | } |
| | 57 | | } |
| | 58 | | } |