38 lines
940 B
C#
38 lines
940 B
C#
|
|
// Copyright (c) The Geekeey Authors
|
||
|
|
// SPDX-License-Identifier: EUPL-1.2
|
||
|
|
|
||
|
|
using System.Linq.Expressions;
|
||
|
|
|
||
|
|
namespace Geekeey.Request.Persistence;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Stores information about a where expression.
|
||
|
|
/// </summary>
|
||
|
|
/// <typeparam name="T">The entity type.</typeparam>
|
||
|
|
public sealed class WhereExpressionInfo<T>
|
||
|
|
{
|
||
|
|
private readonly Lazy<Func<T, bool>> _filterFunc;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Creates a new where expression info.
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="filter">The filter expression.</param>
|
||
|
|
public WhereExpressionInfo(Expression<Func<T, bool>> filter)
|
||
|
|
{
|
||
|
|
ArgumentNullException.ThrowIfNull(filter);
|
||
|
|
|
||
|
|
Filter = filter;
|
||
|
|
|
||
|
|
_filterFunc = new Lazy<Func<T, bool>>(Filter.Compile);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Gets the filter expression.
|
||
|
|
/// </summary>
|
||
|
|
public Expression<Func<T, bool>> Filter { get; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Gets the compiled filter function.
|
||
|
|
/// </summary>
|
||
|
|
public Func<T, bool> FilterFunc => _filterFunc.Value;
|
||
|
|
}
|