< Summary - Code Coverage

Information
Class: Plainquire.Filter.EntityFilter<T>
Assembly: Plainquire.Filter
File(s): /home/runner/work/plainquire/plainquire/Plainquire.Filter/Plainquire.Filter/Filters/EntityFilter.cs
Tag: 66_15485642072
Line coverage
93%
Covered lines: 46
Uncovered lines: 3
Coverable lines: 49
Total lines: 528
Line coverage: 93.8%
Branch coverage
79%
Covered branches: 19
Total branches: 24
Branch coverage: 79.1%
Method coverage
100%
Covered methods: 21
Total methods: 21
Method coverage: 100%

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%11100%
IsEmpty(...)100%44100%
GetPropertyFilterSyntax(...)100%11100%
GetPropertyFilterValues(...)100%11100%
GetNestedFilter(...)100%11100%
GetNestedFilter(...)100%11100%
Add(...)100%11100%
AddNested(...)50%2275%
AddNested(...)100%22100%
Replace(...)100%11100%
ReplaceNested(...)50%2275%
ReplaceNested(...)50%2275%
Remove(...)100%11100%
Clear()100%11100%
Clone()100%11100%
Cast()100%44100%
CreateFilter(...)100%11100%
op_Implicit(...)50%22100%
op_Implicit(...)50%22100%
ToString()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>
 1386027    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)
 1987034        : 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)
 542        => 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)
 250        => 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)
 258        => 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)
 166        => 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>
 176        => 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    {
 11486        AddInternal(property, filters);
 11387        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    {
 298        if (nestedFilter == null)
 099            return this;
 100
 2101        AddNestedInternal(property, nestedFilter);
 2102        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    {
 7115        if (nestedFilter == null)
 6116            return this;
 117
 1118        AddNestedInternal(property, nestedFilter);
 1119        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    {
 10057130        ReplaceInternal(property, filters);
 10057131        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    {
 13142        if (nestedFilter == null)
 0143            return Remove(property);
 144
 13145        ReplaceNestedInternal(property, nestedFilter);
 13146        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    {
 15159        if (nestedFilter == null)
 0160            return Remove(property);
 161
 15162        ReplaceNestedInternal(property, nestedFilter);
 15163        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    {
 11173        RemoveInternal(property);
 11174        return this;
 175    }
 176
 177    /// <summary>
 178    /// Removes all filters of all properties.
 179    /// </summary>
 180    public EntityFilter<TEntity> Clear()
 181    {
 1182        ClearInternal();
 1183        return this;
 184    }
 185
 186    /// <summary>
 187    /// Creates a deep clone of this filter.
 188    /// </summary>
 189    public new EntityFilter<TEntity> Clone()
 3352190        => 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    {
 8199        var castFilter = JsonSerializer.Deserialize<EntityFilter<TDestination>>(JsonSerializer.Serialize(this))!;
 8200        var sourceProperties = typeof(TEntity).GetProperties();
 8201        var destinationProperties = typeof(TDestination).GetProperties().ToList();
 202
 80203        foreach (var sourceProperty in sourceProperties)
 204        {
 32205            var sameDestinationPropertyExists = destinationProperties
 32206                .Exists(x =>
 32207                    x.Name.EqualsOrdinal(sourceProperty.Name) &&
 32208                    x.PropertyType.IsAssignableFrom(sourceProperty.PropertyType)
 32209                );
 210
 32211            if (!sameDestinationPropertyExists)
 212            {
 9213                castFilter.PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(sourceProperty.Name));
 9214                castFilter.NestedFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(sourceProperty.Name));
 215            }
 216        }
 217
 8218        return castFilter;
 219    }
 220
 221    /// <summary>
 222    /// Creates the filter expression. Returns <c>null</c> when filter is empty.
 223    /// </summary>
 224    /// <param name="interceptor">An interceptor to manipulate the generated filters.</param>
 225    /// <param name="useAsCompiledExpression">Whether the generated expression will be compiled later. Used to determine
 226    public Expression<Func<TEntity, bool>>? CreateFilter(IFilterInterceptor? interceptor = null, bool useAsCompiledExpre
 18157227        => CreateFilter<TEntity>(interceptor, useAsCompiledExpression);
 228
 229    /// <summary>
 230    /// Performs an implicit conversion from <see cref="EntityFilter{TEntity}"/> to <see cref="Expression{TDelegate}"/> 
 231    /// </summary>
 232    /// <param name="filter">The filter to convert.</param>
 233    public static implicit operator Expression<Func<TEntity, bool>>(EntityFilter<TEntity> filter)
 1234        => filter.CreateFilter(useAsCompiledExpression: false) ?? (x => true);
 235
 236    /// <summary>
 237    /// Performs an implicit conversion from <see cref="EntityFilter{TEntity}"/> to <see cref="Func{T, TResult}"/>.
 238    /// </summary>
 239    /// <param name="filter">The filter to convert.</param>
 240    public static implicit operator Func<TEntity, bool>(EntityFilter<TEntity> filter)
 8241        => (filter.CreateFilter(useAsCompiledExpression: true) ?? (x => true)).Compile();
 242
 243    /// <inheritdoc />
 244    public override string ToString()
 38245        => CreateFilter()?.ToString() ?? string.Empty;
 246
 247    [ExcludeFromCodeCoverage]
 248    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 249    private string DebuggerDisplay => CreateFilter()?.ToString() ?? "<EMPTY>";
 250}
 251
 252/// <inheritdoc cref="EntityFilter{TEntity}" />
 253[JsonConverter(typeof(EntityFilterConverter))]
 254public class EntityFilter : ICloneable
 255{
 256    private static readonly MethodInfo _createFilterMethod = typeof(EntityFilter).GetMethods(BindingFlags.Instance | Bin
 257
 258    internal List<PropertyFilter> PropertyFilters;
 259    internal List<NestedFilter> NestedFilters;
 260
 261    /// <summary>
 262    /// Gets or sets the default configuration. Can be used to set a system-wide configuration.
 263    /// </summary>
 264    public FilterConfiguration? Configuration { get; internal set; }
 265
 266    /// <summary>
 267    /// Initializes a new instance of the <see cref="EntityFilter"/> class.
 268    /// </summary>
 269    public EntityFilter()
 270    {
 271        PropertyFilters = [];
 272        NestedFilters = [];
 273    }
 274
 275    /// <summary>
 276    /// Initializes a new instance of the <see cref="EntityFilter"/> class.
 277    /// </summary>
 278    /// <param name="configuration">The configuration to use.</param>
 279    public EntityFilter(FilterConfiguration configuration)
 280        : this()
 281        => Configuration = configuration;
 282
 283    /// <inheritdoc />
 284    public object Clone()
 285        => JsonSerializer.Deserialize<EntityFilter>(JsonSerializer.Serialize(this))!;
 286
 287    /// <summary>
 288    /// Indicates whether this filter is empty.
 289    /// </summary>
 290    public bool IsEmpty() => !PropertyFilters.Any() && !NestedFilters.Any();
 291
 292    /// <summary>
 293    /// Indicates whether the specified property filter is empty.
 294    /// </summary>
 295    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 296    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 297    /// <param name="property">The property to get the information for.</param>
 298    public bool IsEmpty<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property)
 299        => GetPropertyFilterValuesInternal(property)?.All(value => value.IsEmpty) ?? true;
 300
 301    /// <summary>
 302    /// Gets the filter syntax for the given <typeparamref name="TProperty"/>.
 303    /// </summary>
 304    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 305    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 306    /// <param name="property">The property to get the filter for.</param>
 307    protected string? GetPropertyFilterSyntaxInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property
 308    {
 309        var propertyName = property.GetPropertyName();
 310        var propertyFilter = PropertyFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName));
 311        return ValueFilterExtensions.ToString(propertyFilter?.ValueFilters);
 312    }
 313
 314    /// <summary>
 315    /// Get the filters applied to the given property.
 316    /// </summary>
 317    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 318    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 319    /// <param name="property">The property to get the filter for.</param>
 320    protected ValueFilter[]? GetPropertyFilterValuesInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> p
 321    {
 322        var propertyName = property.GetPropertyName();
 323        return PropertyFilters.FirstOrDefault(predicate => predicate.PropertyName.EqualsOrdinal(propertyName))?.ValueFil
 324    }
 325
 326    /// <summary>
 327    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested class <typeparamref name="TProperty"/>.
 328    /// </summary>
 329    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 330    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 331    /// <param name="property">The property to get the filter for.</param>
 332    protected EntityFilter<TProperty>? GetNestedFilterInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>>
 333    {
 334        var propertyName = property.GetPropertyName();
 335        return (EntityFilter<TProperty>?)NestedFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName))?.
 336    }
 337
 338    /// <summary>
 339    /// Gets the <see cref="EntityFilter{TProperty}"/> for the given nested list <typeparamref name="TList"/>.
 340    /// </summary>
 341    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 342    /// <typeparam name="TList">The type of the list of <typeparamref name="TProperty"/>.</typeparam>
 343    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 344    /// <param name="property">The property to get the filter for.</param>
 345    protected EntityFilter<TProperty>? GetNestedFilterInternal<TEntity, TList, TProperty>(Expression<Func<TEntity, TList
 346        where TList : IEnumerable<TProperty>
 347    {
 348        var propertyName = property.GetPropertyName();
 349        return (EntityFilter<TProperty>?)NestedFilters.FirstOrDefault(x => x.PropertyName.EqualsOrdinal(propertyName))?.
 350    }
 351
 352    /// <summary>
 353    /// Adds a filter for the given property. Existing filters for the same property are preserved.
 354    /// </summary>
 355    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 356    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 357    /// <param name="property">The property to filter.</param>
 358    /// <param name="valueFilters">The filters to use.</param>
 359    protected void AddInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property, ValueFilter[]? valueF
 360    {
 361        var propertyName = property.GetPropertyName();
 362        PropertyFilters.Add(new PropertyFilter(propertyName, valueFilters));
 363    }
 364
 365    /// <summary>
 366    /// Adds a nested filter for the given property. Existing filters for the same property are preserved.
 367    /// </summary>
 368    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 369    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 370    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 371    /// <param name="property">The property to filter.</param>
 372    /// <param name="nestedFilter">The nested class filter.</param>
 373    protected void AddNestedInternal<TEntity, TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, Entity
 374    {
 375        var propertyName = property.GetPropertyName();
 376        NestedFilters.Add(new NestedFilter(propertyName, nestedFilter));
 377    }
 378
 379    /// <summary>
 380    /// Replaces the filter for the given property using the default filter operator. Existing filters for the same prop
 381    /// </summary>
 382    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 383    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 384    /// <param name="property">The property to filter.</param>
 385    /// <param name="valueFilters">The filters to use.</param>
 386    protected void ReplaceInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property, ValueFilter[]? va
 387    {
 388        var propertyName = property.GetPropertyName();
 389        PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 390        PropertyFilters.Add(new PropertyFilter(propertyName, valueFilters));
 391    }
 392
 393    /// <summary>
 394    /// Replaces the nested filter for the given property. Existing filters for the same property are removed.
 395    /// </summary>
 396    /// <typeparam name="TEntity">The type to be filtered.</typeparam>
 397    /// <typeparam name="TProperty">The type of the property to be filtered.</typeparam>
 398    /// <typeparam name="TNested">The nested type to be filtered.</typeparam>
 399    /// <param name="property">The property to filter.</param>
 400    /// <param name="nestedFilter">The nested class filter.</param>
 401    protected void ReplaceNestedInternal<TEntity, TProperty, TNested>(Expression<Func<TEntity, TProperty?>> property, En
 402    {
 403        var propertyName = property.GetPropertyName();
 404        NestedFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 405        NestedFilters.Add(new NestedFilter(propertyName, nestedFilter));
 406    }
 407
 408    /// <inheritdoc cref="EntityFilter{TEntity}.Remove{TProperty}(Expression{Func{TEntity, TProperty}})" />
 409    protected void RemoveInternal<TEntity, TProperty>(Expression<Func<TEntity, TProperty?>> property)
 410    {
 411        var propertyName = property.GetPropertyName();
 412        PropertyFilters.RemoveAll(x => x.PropertyName.EqualsOrdinal(propertyName));
 413    }
 414
 415    /// <inheritdoc cref="EntityFilter{TEntity}.Clear" />
 416    protected void ClearInternal()
 417        => PropertyFilters.Clear();
 418
 419    /// <inheritdoc cref="EntityFilter{TEntity}.CreateFilter" />
 420    protected internal Expression<Func<TEntity, bool>>? CreateFilter<TEntity>(IFilterInterceptor? interceptor, bool useA
 421    {
 422        var configuration = Configuration ?? FilterConfiguration.Default ?? new FilterConfiguration();
 423        interceptor ??= IFilterInterceptor.Default;
 424
 425        var properties = typeof(TEntity).GetProperties();
 426        var useConditionalAccess = UseConditionalAccess(configuration, useAsCompiledExpression);
 427
 428        var propertyFilters = GetPropertyFilters<TEntity>(properties, interceptor, configuration);
 429        var nestedObjectFilters = GetNestedObjectFilters<TEntity>(properties, useConditionalAccess, interceptor, useAsCo
 430        var nestedListsFilters = CreateNestedListFilters<TEntity>(properties, useConditionalAccess, interceptor, useAsCo
 431
 432        return propertyFilters
 433            .Concat(nestedObjectFilters)
 434            .Concat(nestedListsFilters)
 435            .CombineWithConditionalAnd();
 436    }
 437
 438    private List<Expression<Func<TEntity, bool>>?> GetPropertyFilters<TEntity>(PropertyInfo[] properties, IFilterInterce
 439        => properties
 440            .Reverse()
 441            .Join(
 442                PropertyFilters,
 443                x => x.Name,
 444                x => x.PropertyName,
 445                (propertyInfo, propertyFilter) => new { Property = propertyInfo, propertyFilter.ValueFilters },
 446                StringComparer.Ordinal
 447            )
 448            .Select(x =>
 449                interceptor?.CreatePropertyFilter<TEntity>(x.Property, x.ValueFilters, configuration)
 450                ?? PropertyFilterExpression.CreateFilter<TEntity>(x.Property, x.ValueFilters, configuration, interceptor
 451            )
 452            .ToList();
 453
 454    private List<Expression<Func<TEntity, bool>>?> GetNestedObjectFilters<TEntity>(PropertyInfo[] properties, bool useCo
 455    {
 456        return properties
 457            .Reverse()
 458            .Where(x => !x.PropertyType.IsGenericIEnumerable())
 459            .Join(
 460                NestedFilters,
 461                x => x.Name,
 462                x => x.PropertyName,
 463                (propertyInfo, nestedFilter) => new { Property = propertyInfo, nestedFilter.EntityFilter },
 464                StringComparer.Ordinal
 465            )
 466            .Select(x =>
 467            {
 468                var createFilterExpression = _createFilterMethod.MakeGenericMethod(x.Property.PropertyType);
 469                var nestedFilterExpression = (LambdaExpression?)createFilterExpression.Invoke(x.EntityFilter, [intercept
 470                if (nestedFilterExpression == null)
 471                    return null;
 472
 473                var propertySelector = typeof(TEntity).CreatePropertySelector(x.Property.Name);
 474                var propertyMatchesNested = (Expression<Func<TEntity, bool>>)nestedFilterExpression.ReplaceParameter(pro
 475
 476                if (!useConditionalAccess)
 477                    return propertyMatchesNested;
 478
 479                var propertyIsNotNull = propertySelector.IsNotNull(x.Property.PropertyType);
 480                var propertyIsNotNullLambda = propertySelector.CreateLambda<TEntity, bool>(propertyIsNotNull);
 481
 482                var filterExpression = new[] { propertyIsNotNullLambda, propertyMatchesNested }.CombineWithConditionalAn
 483                return filterExpression;
 484            })
 485            .ToList();
 486    }
 487
 488    private List<Expression<Func<TEntity, bool>>?> CreateNestedListFilters<TEntity>(PropertyInfo[] properties, bool useC
 489        => properties
 490            .Reverse()
 491            .Where(x => x.PropertyType.IsGenericIEnumerable())
 492            .Join(
 493                NestedFilters,
 494                x => x.Name,
 495                x => x.PropertyName,
 496                (propertyInfo, nestedFilter) => new { Property = propertyInfo, nestedFilter.EntityFilter },
 497                StringComparer.Ordinal
 498            )
 499            .Select(x =>
 500            {
 501                var propertyType = x.Property.PropertyType.GetGenericArguments()[0];
 502                var createFilterExpression = _createFilterMethod.MakeGenericMethod(propertyType);
 503                var nestedFilterExpression = (LambdaExpression?)createFilterExpression.Invoke(x.EntityFilter, [intercept
 504                if (nestedFilterExpression == null)
 505                    return null;
 506
 507                var propertySelector = typeof(TEntity).CreatePropertySelector(x.Property.Name);
 508                var propertyHasAnyNested = (Expression<Func<TEntity, bool>>)propertySelector.EnumerableAny(propertyType,
 509
 510                if (!useConditionalAccess)
 511                    return propertyHasAnyNested;
 512
 513                var propertyIsNotNull = propertySelector.IsNotNull(x.Property.PropertyType);
 514                var propertyIsNotNullLambda = propertySelector.CreateLambda<TEntity, bool>(propertyIsNotNull);
 515
 516                var filterExpression = new[] { propertyIsNotNullLambda, propertyHasAnyNested }.CombineWithConditionalAnd
 517                return filterExpression;
 518            })
 519            .ToList();
 520
 521    private static bool UseConditionalAccess(FilterConfiguration configuration, bool usedAsCompiledExpression)
 522        => configuration.UseConditionalAccess switch
 523        {
 524            FilterConditionalAccess.Always => true,
 525            FilterConditionalAccess.Never => false,
 526            _ => usedAsCompiledExpression
 527        };
 528}

Methods/Properties

.ctor()
.ctor(Plainquire.Filter.Abstractions.FilterConfiguration)
IsEmpty(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
GetPropertyFilterSyntax(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
GetPropertyFilterValues(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
GetNestedFilter(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
GetNestedFilter(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TList>>)
Add(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.ValueFilter[])
AddNested(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.EntityFilter`1<TProperty>)
AddNested(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.EntityFilter`1<TNested>)
Replace(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.ValueFilter[])
ReplaceNested(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.EntityFilter`1<TProperty>)
ReplaceNested(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>,Plainquire.Filter.EntityFilter`1<TNested>)
Remove(System.Linq.Expressions.Expression`1<System.Func`2<TEntity,TProperty>>)
Clear()
Clone()
Cast()
CreateFilter(Plainquire.Filter.IFilterInterceptor,System.Boolean)
op_Implicit(Plainquire.Filter.EntityFilter`1<TEntity>)
op_Implicit(Plainquire.Filter.EntityFilter`1<TEntity>)
ToString()