< Summary - Code Coverage

Information
Class: Plainquire.Filter.EntityFilter
Assembly: Plainquire.Filter
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/Filters/EntityFilter.cs
Tag: 74_23635074410
Line coverage
98%
Covered lines: 126
Uncovered lines: 2
Coverable lines: 128
Total lines: 507
Line coverage: 98.4%
Branch coverage
84%
Covered branches: 39
Total branches: 46
Branch coverage: 84.7%
Method coverage
90%
Covered methods: 19
Total methods: 21
Method coverage: 90.4%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
Clone()100%110%
IsEmpty()100%22100%
IsEmpty(...)0%440%
Clear()100%11100%
GetPropertyFilterSyntaxInternal(...)50%22100%
GetPropertyFilterValuesInternal(...)100%22100%
GetNestedFilterInternal(...)50%22100%
GetNestedFilterInternal(...)50%22100%
AddInternal(...)100%11100%
AddNestedInternal(...)100%11100%
ReplaceInternal(...)100%11100%
ReplaceNestedInternal(...)100%11100%
RemoveInternal(...)100%11100%
CreateFilter(...)100%66100%
GetPropertyFilters(...)100%66100%
GetNestedObjectFilters(...)100%88100%
CreateNestedListFilters(...)100%88100%
UseConditionalAccess(...)100%44100%

File(s)

/home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/Filters/EntityFilter.cs

#LineLine coverage
 1using Plainquire.Filter.Abstractions;
 2using Plainquire.Filter.JsonConverters;
 3using Plainquire.Filter.PropertyFilterExpressions;
 4using System;
 5using System.Collections.Generic;
 6using System.Diagnostics;
 7using System.Diagnostics.CodeAnalysis;
 8using System.Linq;
 9using System.Linq.Expressions;
 10using System.Reflection;
 11using System.Text.Json;
 12using System.Text.Json.Serialization;
 13
 14namespace Plainquire.Filter;
 15
 16/// <summary>
 17/// Hub to create filter expressions for <typeparamref name="TEntity"/> with fluent API.
 18/// </summary>
 19/// <typeparam name="TEntity">The type to be filtered.</typeparam>
 20[JsonConverter(typeof(EntityFilterConverter.Factory))]
 21[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
 22public class EntityFilter<TEntity> : EntityFilter
 23{
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="EntityFilter{TEntity}"/> class.
 26    /// </summary>
 27    public EntityFilter() { }
 28
 29    /// <summary>
 30    /// Initializes a new instance of the <see cref="EntityFilter{TEntity}"/> class.
 31    /// </summary>
 32    /// <param name="configuration">The configuration to use.</param>
 33    public EntityFilter(FilterConfiguration configuration)
 34        : base(configuration) { }
 35
 36    /// <summary>
 37    /// Indicates whether the filter for the specified property is empty.
 38    /// </summary>
 39    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 40    /// <param name="property">The property to get the information for.</param>
 41    public bool IsEmpty<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 42        => GetPropertyFilterValuesInternal(property)?.All(value => value.IsEmpty) ?? true;
 43
 44    /// <summary>
 45    /// Gets the filter syntax for the given <paramref name="property"/>.
 46    /// </summary>
 47    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 48    /// <param name="property">The property to get the filter for.</param>
 49    public string? GetPropertyFilterSyntax<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 50        => GetPropertyFilterSyntaxInternal(property);
 51
 52    /// <summary>
 53    /// Get the filters applied to the given property.
 54    /// </summary>
 55    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 56    /// <param name="property">The property to get the filter for.</param>
 57    public ValueFilter[]? GetPropertyFilterValues<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 58        => GetPropertyFilterValuesInternal(property);
 59
 60    /// <summary>
 61    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested class <typeparamref name="TProperty"/>.
 62    /// </summary>
 63    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 64    /// <param name="property">The property to get the filter for.</param>
 65    public EntityFilter<TProperty>? GetNestedFilter<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 66        => GetNestedFilterInternal(property);
 67
 68    /// <summary>
 69    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested list <typeparamref name="TList"/>.
 70    /// </summary>
 71    /// <typeparam name="TList">The type of the list of <typeparamref name="TProperty"/>.</typeparam>
 72    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 73    /// <param name="property">The property to get the filter for.</param>
 74    public EntityFilter<TProperty>? GetNestedFilter<TList, TProperty>(Expression<Func<TEntity, TList?>> property)
 75        where TList : IEnumerable<TProperty>
 76        => GetNestedFilterInternal<TEntity, TList, TProperty>(property);
 77
 78    /// <summary>
 79    /// Adds a filter for the given property. Existing filters for the same property are preserved.
 80    /// </summary>
 81    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 82    /// <param name="property">The property to filter.</param>
 83    /// <param name="filters">The filters to use.</param>
 84    public EntityFilter<TEntity> Add<TProperty>(Expression<Func<TEntity, TProperty?>> property, params ValueFilter[]? fi
 85    {
 86        AddInternal(property, filters);
 87        return this;
 88    }
 89
 90    /// <summary>
 91    /// Adds a nested filter for the given property. Existing filters for the same property are preserved.
 92    /// </summary>
 93    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 94    /// <param name="property">The property to filter.</param>
 95    /// <param name="nestedFilter">The nested class filter.</param>
 96    public EntityFilter<TEntity> AddNested<TProperty>(Expression<Func<TEntity, TProperty?>> property, EntityFilter<TProp
 97    {
 98        if (nestedFilter == null)
 99            return this;
 100
 101        AddNestedInternal(property, nestedFilter);
 102        return this;
 103    }
 104
 105    /// <summary>
 106    /// Adds a nested filter for the given enumerable property. Existing filters for the same property are preserved.
 107    /// </summary>
 108    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 109    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 110    /// <param name="property">The property to filter. Must implement <see cref="IEnumerable{T}"/>.</param>
 111    /// <param name="nestedFilter">The nested class filter.</param>
 112    public EntityFilter<TEntity> AddNested<TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, EntityFil
 113        where TProperty : IEnumerable<TNested>
 114    {
 115        if (nestedFilter == null)
 116            return this;
 117
 118        AddNestedInternal(property, nestedFilter);
 119        return this;
 120    }
 121
 122    /// <summary>
 123    /// Replaces the filter for the given property. Existing filters for the same property are removed.
 124    /// </summary>
 125    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 126    /// <param name="property">The property to filter.</param>
 127    /// <param name="filters">The filters to use.</param>
 128    public EntityFilter<TEntity> Replace<TProperty>(Expression<Func<TEntity, TProperty?>> property, params ValueFilter[]
 129    {
 130        ReplaceInternal(property, filters);
 131        return this;
 132    }
 133
 134    /// <summary>
 135    /// Replaces the nested filter for the given property. Existing filters for the same property are removed.
 136    /// </summary>
 137    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 138    /// <param name="property">The property to filter.</param>
 139    /// <param name="nestedFilter">The nested class filter.</param>
 140    public EntityFilter<TEntity> ReplaceNested<TProperty>(Expression<Func<TEntity, TProperty?>> property, EntityFilter<T
 141    {
 142        if (nestedFilter == null)
 143            return Remove(property);
 144
 145        ReplaceNestedInternal(property, nestedFilter);
 146        return this;
 147    }
 148
 149    /// <summary>
 150    /// Replaces the nested filter for the given enumerable property. Existing filters for the same property are removed
 151    /// </summary>
 152    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 153    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 154    /// <param name="property">The property to filter. Must implement <see cref="IEnumerable{T}"/>.</param>
 155    /// <param name="nestedFilter">The nested class filter.</param>
 156    public EntityFilter<TEntity> ReplaceNested<TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, Entit
 157        where TProperty : IEnumerable<TNested>
 158    {
 159        if (nestedFilter == null)
 160            return Remove(property);
 161
 162        ReplaceNestedInternal(property, nestedFilter);
 163        return this;
 164    }
 165
 166    /// <summary>
 167    /// Remove all filters for the specified property.
 168    /// </summary>
 169    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 170    /// <param name="property">The property to remove all filters for.</param>
 171    public EntityFilter<TEntity> Remove<TProperty>(Expression<Func<TEntity, TProperty?>> property)
 172    {
 173        RemoveInternal(property);
 174        return this;
 175    }
 176
 177    /// <summary>
 178    /// Removes all filters of all properties.
 179    /// </summary>
 180    public new EntityFilter<TEntity> Clear()
 181    {
 182        base.Clear();
 183        return this;
 184    }
 185
 186    /// <summary>
 187    /// Creates a deep clone of this filter.
 188    /// </summary>
 189    public new EntityFilter<TEntity> Clone()
 190        => JsonSerializer.Deserialize<EntityFilter<TEntity>>(JsonSerializer.Serialize(this))!;
 191
 192    /// <summary>
 193    /// Casts this filter to a different type (by creating a deep clone).
 194    /// Filtered properties are matched by type (check if assignable) and name (case-sensitive).
 195    /// </summary>
 196    /// <typeparam name="TDestination">The type of the destination entity to filter.</typeparam>
 197    public EntityFilter<TDestination> Cast<TDestination>()
 198        => this.Cast<TEntity, TDestination>();
 199
 200    /// <summary>
 201    /// Creates the filter expression. Returns <c>null</c> when filter is empty.
 202    /// </summary>
 203    /// <param name="interceptor">An interceptor to manipulate the generated filters.</param>
 204    /// <param name="useAsCompiledExpression">Whether the generated expression will be compiled later. Used to determine
 205    public Expression<Func<TEntity, bool>>? CreateFilter(IFilterInterceptor? interceptor = null, bool useAsCompiledExpre
 206        => CreateFilter<TEntity>(interceptor, useAsCompiledExpression);
 207
 208    /// <summary>
 209    /// Performs an implicit conversion from <see cref="EntityFilter{TEntity}"/> to <see cref="Expression{TDelegate}"/> 
 210    /// </summary>
 211    /// <param name="filter">The filter to convert.</param>
 212    public static implicit operator Expression<Func<TEntity, bool>>(EntityFilter<TEntity> filter)
 213        => filter.CreateFilter(useAsCompiledExpression: false) ?? (x => true);
 214
 215    /// <summary>
 216    /// Performs an implicit conversion from <see cref="EntityFilter{TEntity}"/> to <see cref="Func{T, TResult}"/>.
 217    /// </summary>
 218    /// <param name="filter">The filter to convert.</param>
 219    public static implicit operator Func<TEntity, bool>(EntityFilter<TEntity> filter)
 220        => (filter.CreateFilter(useAsCompiledExpression: true) ?? (x => true)).Compile();
 221
 222    /// <inheritdoc />
 223    public override string ToString()
 224        => CreateFilter()?.ToString() ?? string.Empty;
 225
 226    [ExcludeFromCodeCoverage]
 227    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 228    private string DebuggerDisplay => CreateFilter()?.ToString() ?? "<EMPTY>";
 229}
 230
 231/// <inheritdoc cref="EntityFilter{TEntity}" />
 232[JsonConverter(typeof(EntityFilterConverter))]
 233public class EntityFilter : ICloneable
 234{
 1235    private static readonly MethodInfo _createFilterMethod = typeof(EntityFilter).GetMethods(BindingFlags.Instance | Bin
 236
 237    internal List<PropertyFilter> PropertyFilters;
 238    internal List<NestedFilter> NestedFilters;
 239
 240    /// <summary>
 241    /// Gets or sets the default configuration. Can be used to set a system-wide configuration.
 242    /// </summary>
 243    public FilterConfiguration? Configuration { get; internal set; }
 244
 245    /// <summary>
 246    /// Initializes a new instance of the <see cref="EntityFilter"/> class.
 247    /// </summary>
 248    public EntityFilter()
 249    {
 16892250        PropertyFilters = [];
 16892251        NestedFilters = [];
 16892252    }
 253
 254    /// <summary>
 255    /// Initializes a new instance of the <see cref="EntityFilter"/> class.
 256    /// </summary>
 257    /// <param name="configuration">The configuration to use.</param>
 258    public EntityFilter(FilterConfiguration configuration)
 9935259        : this()
 9935260        => Configuration = configuration;
 261
 262    /// <inheritdoc />
 263    public object Clone()
 0264        => JsonSerializer.Deserialize<EntityFilter>(JsonSerializer.Serialize(this))!;
 265
 266    /// <summary>
 267    /// Indicates whether this filter is empty.
 268    /// </summary>
 4269    public bool IsEmpty() => !PropertyFilters.Any() && !NestedFilters.Any();
 270
 271    /// <summary>
 272    /// Indicates whether the specified property filter is empty.
 273    /// </summary>
 274    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 275    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 276    /// <param name="property">The property to get the information for.</param>
 277    public bool IsEmpty<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property)
 0278        => GetPropertyFilterValuesInternal(property)?.All(value => value.IsEmpty) ?? true;
 279
 280    /// <inheritdoc cref="EntityFilter{TEntity}.Clear" />
 281    public void Clear()
 1282        => PropertyFilters.Clear();
 283
 284    /// <summary>
 285    /// Gets the filter syntax for the given <typeparamref name="TProperty"/>.
 286    /// </summary>
 287    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 288    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 289    /// <param name="property">The property to get the filter for.</param>
 290    protected string? GetPropertyFilterSyntaxInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property
 291    {
 2292        var propertyName = property.GetPropertyName();
 2293        var propertyFilter = PropertyFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName));
 2294        return ValueFilterExtensions.ToString(propertyFilter?.ValueFilters);
 295    }
 296
 297    /// <summary>
 298    /// Get the filters applied to the given property.
 299    /// </summary>
 300    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 301    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 302    /// <param name="property">The property to get the filter for.</param>
 303    protected ValueFilter[]? GetPropertyFilterValuesInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> p
 304    {
 7305        var propertyName = property.GetPropertyName();
 7306        return PropertyFilters.FirstOrDefault(predicate => predicate.PropertyName.EqualsOrdinal(propertyName))?.ValueFil
 307    }
 308
 309    /// <summary>
 310    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested class <typeparamref name="TProperty"/>.
 311    /// </summary>
 312    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 313    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 314    /// <param name="property">The property to get the filter for.</param>
 315    protected EntityFilter<TProperty>? GetNestedFilterInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>>
 316    {
 1317        var propertyName = property.GetPropertyName();
 1318        return (EntityFilter<TProperty>?)NestedFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName))?.
 319    }
 320
 321    /// <summary>
 322    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested list <typeparamref name="TList"/>.
 323    /// </summary>
 324    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 325    /// <typeparam name="TList">The type of the list of <typeparamref name="TProperty"/>.</typeparam>
 326    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 327    /// <param name="property">The property to get the filter for.</param>
 328    protected EntityFilter<TProperty>? GetNestedFilterInternal<TEntity, TList, TProperty>(Expression<Func<TEntity, TList
 329        where TList : IEnumerable<TProperty>
 330    {
 1331        var propertyName = property.GetPropertyName();
 1332        return (EntityFilter<TProperty>?)NestedFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName))?.
 333    }
 334
 335    /// <summary>
 336    /// Adds a filter for the given property. Existing filters for the same property are preserved.
 337    /// </summary>
 338    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 339    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 340    /// <param name="property">The property to filter.</param>
 341    /// <param name="valueFilters">The filters to use.</param>
 342    protected void AddInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property, ValueFilter[]? valueF
 343    {
 114344        var propertyName = property.GetPropertyName();
 113345        PropertyFilters.Add(new PropertyFilter(propertyName, valueFilters));
 113346    }
 347
 348    /// <summary>
 349    /// Adds a nested filter for the given property. Existing filters for the same property are preserved.
 350    /// </summary>
 351    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 352    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 353    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 354    /// <param name="property">The property to filter.</param>
 355    /// <param name="nestedFilter">The nested class filter.</param>
 356    protected void AddNestedInternal<TEntity, TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, Entity
 357    {
 3358        var propertyName = property.GetPropertyName();
 3359        NestedFilters.Add(new NestedFilter(propertyName, nestedFilter));
 3360    }
 361
 362    /// <summary>
 363    /// Replaces the filter for the given property using the default filter operator. Existing filters for the same prop
 364    /// </summary>
 365    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 366    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 367    /// <param name="property">The property to filter.</param>
 368    /// <param name="valueFilters">The filters to use.</param>
 369    protected void ReplaceInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property, ValueFilter[]? va
 370    {
 10057371        var propertyName = property.GetPropertyName();
 10057372        PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 10057373        PropertyFilters.Add(new PropertyFilter(propertyName, valueFilters));
 10057374    }
 375
 376    /// <summary>
 377    /// Replaces the nested filter for the given property. Existing filters for the same property are removed.
 378    /// </summary>
 379    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 380    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 381    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 382    /// <param name="property">The property to filter.</param>
 383    /// <param name="nestedFilter">The nested class filter.</param>
 384    protected void ReplaceNestedInternal<TEntity, TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, En
 385    {
 28386        var propertyName = property.GetPropertyName();
 28387        NestedFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 28388        NestedFilters.Add(new NestedFilter(propertyName, nestedFilter));
 28389    }
 390
 391    /// <inheritdoc cref="EntityFilter{TEntity}.Remove{TProperty}(Expression{Func{TEntity, TProperty}})" />
 392    protected void RemoveInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property)
 393    {
 11394        var propertyName = property.GetPropertyName();
 11395        PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 11396    }
 397
 398    /// <inheritdoc cref="EntityFilter{TEntity}.CreateFilter" />
 399    protected internal Expression<Func<TEntity, bool>>? CreateFilter<TEntity>(IFilterInterceptor? interceptor, bool useA
 400    {
 18196401        var configuration = Configuration ?? FilterConfiguration.Default ?? new FilterConfiguration();
 18196402        interceptor ??= IFilterInterceptor.Default;
 403
 18196404        var properties = typeof(TEntity).GetProperties();
 18196405        var useConditionalAccess = UseConditionalAccess(configuration, useAsCompiledExpression);
 406
 18196407        var propertyFilters = GetPropertyFilters<TEntity>(properties, interceptor, configuration);
 16316408        var nestedObjectFilters = GetNestedObjectFilters<TEntity>(properties, useConditionalAccess, interceptor, useAsCo
 16316409        var nestedListsFilters = CreateNestedListFilters<TEntity>(properties, useConditionalAccess, interceptor, useAsCo
 410
 16316411        return propertyFilters
 16316412            .Concat(nestedObjectFilters)
 16316413            .Concat(nestedListsFilters)
 16316414            .CombineWithConditionalAnd();
 415    }
 416
 417    private List<Expression<Func<TEntity, bool>>?> GetPropertyFilters<TEntity>(PropertyInfo[] properties, IFilterInterce
 18196418        => properties
 18196419            .Reverse()
 18196420            .Join(
 18196421                PropertyFilters,
 18196422                x => x.Name,
 18196423                x => x.PropertyName,
 18196424                (propertyInfo, propertyFilter) => new { Property = propertyInfo, propertyFilter.ValueFilters },
 18196425                StringComparer.Ordinal
 18196426            )
 18196427            .Select(x =>
 18196428                interceptor?.CreatePropertyFilter<TEntity>(x.Property, x.ValueFilters, configuration)
 18196429                ?? PropertyFilterExpression.CreateFilter<TEntity>(x.Property, x.ValueFilters, configuration, interceptor
 18196430            )
 18196431            .ToList();
 432
 433    private List<Expression<Func<TEntity, bool>>?> GetNestedObjectFilters<TEntity>(PropertyInfo[] properties, bool useCo
 434    {
 16316435        return properties
 16316436            .Reverse()
 16316437            .Where(x => !x.PropertyType.IsGenericIEnumerable())
 16316438            .Join(
 16316439                NestedFilters,
 16316440                x => x.Name,
 16316441                x => x.PropertyName,
 16316442                (propertyInfo, nestedFilter) => new { Property = propertyInfo, nestedFilter.EntityFilter },
 16316443                StringComparer.Ordinal
 16316444            )
 16316445            .Select(x =>
 16316446            {
 16316447                var createFilterExpression = _createFilterMethod.MakeGenericMethod(x.Property.PropertyType);
 16316448                var nestedFilterExpression = (LambdaExpression?)createFilterExpression.Invoke(x.EntityFilter, [intercept
 16316449                if (nestedFilterExpression == null)
 16316450                    return null;
 16316451
 16316452                var propertySelector = typeof(TEntity).CreatePropertySelector(x.Property.Name);
 16316453                var propertyMatchesNested = (Expression<Func<TEntity, bool>>)nestedFilterExpression.ReplaceParameter(pro
 16316454
 16316455                if (!useConditionalAccess)
 16316456                    return propertyMatchesNested;
 16316457
 16316458                var propertyIsNotNull = propertySelector.IsNotNull(x.Property.PropertyType);
 16316459                var propertyIsNotNullLambda = propertySelector.CreateLambda<TEntity, bool>(propertyIsNotNull);
 16316460
 16316461                var filterExpression = new[] { propertyIsNotNullLambda, propertyMatchesNested }.CombineWithConditionalAn
 16316462                return filterExpression;
 16316463            })
 16316464            .ToList();
 465    }
 466
 467    private List<Expression<Func<TEntity, bool>>?> CreateNestedListFilters<TEntity>(PropertyInfo[] properties, bool useC
 16316468        => properties
 16316469            .Reverse()
 16316470            .Where(x => x.PropertyType.IsGenericIEnumerable())
 16316471            .Join(
 16316472                NestedFilters,
 16316473                x => x.Name,
 16316474                x => x.PropertyName,
 16316475                (propertyInfo, nestedFilter) => new { Property = propertyInfo, nestedFilter.EntityFilter },
 16316476                StringComparer.Ordinal
 16316477            )
 16316478            .Select(x =>
 16316479            {
 16316480                var propertyType = x.Property.PropertyType.GetGenericArguments()[0];
 16316481                var createFilterExpression = _createFilterMethod.MakeGenericMethod(propertyType);
 16316482                var nestedFilterExpression = (LambdaExpression?)createFilterExpression.Invoke(x.EntityFilter, [intercept
 16316483                if (nestedFilterExpression == null)
 16316484                    return null;
 16316485
 16316486                var propertySelector = typeof(TEntity).CreatePropertySelector(x.Property.Name);
 16316487                var propertyHasAnyNested = (Expression<Func<TEntity, bool>>)propertySelector.EnumerableAny(propertyType,
 16316488
 16316489                if (!useConditionalAccess)
 16316490                    return propertyHasAnyNested;
 16316491
 16316492                var propertyIsNotNull = propertySelector.IsNotNull(x.Property.PropertyType);
 16316493                var propertyIsNotNullLambda = propertySelector.CreateLambda<TEntity, bool>(propertyIsNotNull);
 16316494
 16316495                var filterExpression = new[] { propertyIsNotNullLambda, propertyHasAnyNested }.CombineWithConditionalAnd
 16316496                return filterExpression;
 16316497            })
 16316498            .ToList();
 499
 500    private static bool UseConditionalAccess(FilterConfiguration configuration, bool usedAsCompiledExpression)
 18196501        => configuration.UseConditionalAccess switch
 18196502        {
 2503            FilterConditionalAccess.Always => true,
 2504            FilterConditionalAccess.Never => false,
 18192505            _ => usedAsCompiledExpression
 18196506        };
 507}

Methods/Properties

.cctor()
.ctor()
.ctor(Plainquire.Filter.Abstractions.FilterConfiguration)
Clone()
IsEmpty()
IsEmpty(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
Clear()
GetPropertyFilterSyntaxInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
GetPropertyFilterValuesInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
GetNestedFilterInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
GetNestedFilterInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TList>>)
AddInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.ValueFilter[])
AddNestedInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.EntityFilter`1<TNested>)
ReplaceInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.ValueFilter[])
ReplaceNestedInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.EntityFilter`1<TNested>)
RemoveInternal(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
CreateFilter(Plainquire.Filter.IFilterInterceptor,System.Boolean)
GetPropertyFilters(System.Reflection.PropertyInfo[],Plainquire.Filter.IFilterInterceptor,Plainquire.Filter.Abstractions.FilterConfiguration)
GetNestedObjectFilters(System.Reflection.PropertyInfo[],System.Boolean,Plainquire.Filter.IFilterInterceptor,System.Boolean)
CreateNestedListFilters(System.Reflection.PropertyInfo[],System.Boolean,Plainquire.Filter.IFilterInterceptor,System.Boolean)
UseConditionalAccess(Plainquire.Filter.Abstractions.FilterConfiguration,System.Boolean)