using System.Linq.Expressions; using ZeroFramework.DeviceCenter.Domain.Specifications.Builder; using ZeroFramework.DeviceCenter.Domain.Specifications.Evaluators; namespace ZeroFramework.DeviceCenter.Domain.Specifications { public abstract class Specification : Specification, ISpecification { protected new virtual ISpecificationBuilder Query { get; } protected Specification() : this(InMemorySpecificationEvaluator.Default) { } protected Specification(IInMemorySpecificationEvaluator inMemorySpecificationEvaluator) : base(inMemorySpecificationEvaluator) { this.Query = new SpecificationBuilder(this); } public new virtual IEnumerable Evaluate(IEnumerable entities) { return Evaluator.Evaluate(entities, this); } public Expression>? Selector { get; internal set; } public new Func, IEnumerable>? PostProcessingAction { get; internal set; } = null; } public abstract class Specification : ISpecification { protected IInMemorySpecificationEvaluator Evaluator { get; } protected virtual ISpecificationBuilder Query { get; } protected Specification() : this(InMemorySpecificationEvaluator.Default) { } protected Specification(IInMemorySpecificationEvaluator inMemorySpecificationEvaluator) { this.Evaluator = inMemorySpecificationEvaluator; this.Query = new SpecificationBuilder(this); } public virtual IEnumerable Evaluate(IEnumerable entities) { return Evaluator.Evaluate(entities, this); } public IEnumerable>> WhereExpressions { get; } = new List>>(); public IEnumerable<(Expression> KeySelector, OrderTypeEnum OrderType)> OrderExpressions { get; } = new List<(Expression> KeySelector, OrderTypeEnum OrderType)>(); public IEnumerable IncludeExpressions { get; } = new List(); public IEnumerable IncludeStrings { get; } = new List(); public IEnumerable<(Expression> Selector, string SearchTerm, int SearchGroup)> SearchCriterias { get; } = new List<(Expression> Selector, string SearchTerm, int SearchGroup)>(); public int? Take { get; internal set; } = null; public int? Skip { get; internal set; } = null; public Func, IEnumerable>? PostProcessingAction { get; internal set; } = null; public string? CacheKey { get; internal set; } public bool CacheEnabled { get; internal set; } public bool AsNoTracking { get; internal set; } = false; public bool AsSplitQuery { get; internal set; } = false; public bool AsNoTrackingWithIdentityResolution { get; internal set; } = false; } }