Repository navigation
OnixLabs.Core.CriteriaSpecification
Represents a concrete specification that wraps a supplied Expression<Func<T, bool>> directly, without requiring a dedicated derived class.
| Namespace | OnixLabs.Core |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → Specification<T> → CriteriaSpecification<T>
|
public class CriteriaSpecification<T>(Expression<Func<T, bool>> criteria) : Specification<T>| Parameter | Description |
|---|---|
T |
The underlying type of the subject to which the specification applies. |
CriteriaSpecification<T> is the simplest way to create a specification: pass an expression to the primary constructor and the type exposes it as Criteria. It is useful when a rule does not warrant its own named class.
CriteriaSpecification<T> is also used internally by the And(Specification<T>), Or(Specification<T>), and Not() combinators of Specification<T> — each combinator constructs a CriteriaSpecification<T> whose expression is the composed or negated form of the operand expressions, so composed specifications remain fully translatable by a LINQ provider.
Because CriteriaSpecification<T> inherits all combinators from Specification<T>, a wrapped expression composes with derived specifications and other CriteriaSpecification<T> instances identically.
using System;
using System.Linq.Expressions;
using OnixLabs.Core;
public sealed record Customer(string Name, int Age, bool IsActive);
Specification<Customer> isAdult = new CriteriaSpecification<Customer>(customer => customer.Age >= 18);
bool result = isAdult.IsSatisfiedBy(new Customer("Alice", 30, true)); // trueSpecification<Customer> isAdult = new CriteriaSpecification<Customer>(c => c.Age >= 18);
Specification<Customer> isActive = new CriteriaSpecification<Customer>(c => c.IsActive);
// Wrapped specifications compose just like derived ones.
Specification<Customer> activeAdult = isAdult.And(isActive);
bool result = activeAdult.IsSatisfiedBy(new Customer("Bob", 40, true)); // truepublic sealed class IsAdultSpecification : Specification<Customer>
{
public override Expression<Func<Customer, bool>> Criteria => c => c.Age >= 18;
}
Specification<Customer> isActive = new CriteriaSpecification<Customer>(c => c.IsActive);
Specification<Customer> activeAdult = new IsAdultSpecification().And(isActive);| Constructor | Description |
|---|---|
CriteriaSpecification(Expression<Func<T, bool>>) |
Initializes a new instance of the CriteriaSpecification<T> class with the specified criteria. |
public CriteriaSpecification(Expression<Func<T, bool>> criteria)Initializes a new instance of the CriteriaSpecification<T> class that wraps the specified expression criteria.
| Parameter | Type | Description |
|---|---|---|
criteria |
Expression<Func<T, bool>> |
The expression criteria to wrap. |
| Property | Type | Description |
|---|---|---|
Criteria |
Expression<Func<T, bool>> |
Gets the wrapped expression criteria of the current specification. |
public override Expression<Func<T, bool>> Criteria { get; }Gets the expression criteria supplied to the constructor. Overrides Specification<T>.Criteria.
ONIXLabs .NET Library · Repository · NuGet · License (Apache-2.0)
Copyright © ONIXLabs 2020. Licensed under the Apache License, Version 2.0.
- Enumeration<T>
- Optional<T>
- OptionalEqualityComparer<T>
- OptionalExtensions
- Result
- Result<T>
- ResultEqualityComparer<T>
- ResultExtensions
- Specification<T>
- Preconditions
- IValueEquatable<T>
- IValueComparable<T>
- IBinaryConvertible
- ISpanBinaryConvertible
- IMemoryBinaryConvertible
- ArrayExtensions
- ComparableExtensions
- DateTimeExtensions
- ISpanParsableExtensions
- ObjectExtensions
- RandomExtensions
- ReadOnlySequenceExtensions
- ReadOnlySpanExtensions
- StringExtensions
- Base16
- Base32
- Base58
- Base64
- IBaseCodec
- IBaseValue
- IBaseValue<T>
- Base16Codec
- Base32Codec
- Base58Codec
- Base64Codec
- Base16FormatProvider
- Base32FormatProvider
- Base58FormatProvider
- Base64FormatProvider
- EncodingExtensions
- ReadOnlySpanExtensions
- StringBuilderExtensions
- BigDecimal
- BigDecimalEqualityComparer
- BigDecimalOrdinalityComparer
- NumberInfo
- NumberInfoEqualityComparer
- NumberInfoOrdinalityComparer
- Int256
- Int512
- UInt256
- UInt512
- Float128
- Float256
- GenericMath
- NumericsExtensions
- ConversionMode
- ScaleMode
- Hash
- NamedHash
- Sha3
- Sha3Hash224
- Sha3Hash256
- Sha3Hash384
- Sha3Hash512
- Sha3Shake128
- Sha3Shake256
- MerkleTree
- MerkleTree<T>
- PrivateKey
- PublicKey
- NamedPrivateKey
- NamedPublicKey
- EcdhPrivateKey
- EcdhPublicKey
- EcdsaPrivateKey
- EcdsaPublicKey
- EddsaPrivateKey
- EddsaPublicKey
- RsaPrivateKey
- RsaPublicKey
- DigitalSignature
- DigitalSignatureAndPublicKey
- Salt
- Secret
- ICryptoPrimitive<T>
- IHashable
- IEcdhPrivateKey
- IEcdsaPrivateKey
- IEddsaPrivateKey
- IRsaPrivateKey
- IPrivateKeyDerivable<T>
- IPrivateKeyExportable
- IPrivateKeyImportable<T>
- IPrivateKeyPemImportable<T>
- IPrivateKeyPkcs8Exportable
- IPrivateKeyPkcs8Importable<T>
- IPrivateKeyPkcs8PemExportable
- IPrivateKeyRawExportable
- IPrivateKeyRawImportable<T>
- IPrivateKeyRawPemExportable
- IEcdhPublicKey
- IEcdsaPublicKey
- IEddsaPublicKey
- IRsaPublicKey
- IPublicKeyExportable
- IPublicKeyImportable<T>
- IPublicKeyPemExportable
- IPublicKeyPemImportable<T>
- IPublicKeyRawExportable
- IPublicKeyRawImportable<T>
- HashAlgorithmExtensions
- ReadOnlySpanExtensions