Repository navigation
OnixLabs.Core.Linq.ExpressionExtensions
Provides extension methods for Expression<TDelegate> instances, enabling boolean predicate expressions to be combined with logical AND / OR and negated with logical NOT.
| Namespace | OnixLabs.Core.Linq |
| Assembly | OnixLabs.Core.dll (NuGet) |
| Inheritance |
object → ExpressionExtensions
|
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ExpressionExtensionsNote
ExpressionExtensionsis decorated with[EditorBrowsable(EditorBrowsableState.Never)]. Although the class ispublic, it is hidden from IntelliSense completion lists so that only the extension methods themselves appear on their receiver types. Bring the extensions into scope withusing OnixLabs.Core.Linq;.This class uses a C# 14 extension block (
extension<T>(Expression<Func<T, bool>> receiver) { ... }), so the receiver type appears in the block declaration rather than as athisparameter. The signatures shown below are the call-site signatures as consumed by user code.
All three methods in this class operate over a receiver of type Expression<Func<T, bool>> — a boolean predicate expression. When combining or negating expressions, each method introduces a fresh, shared parameter (named $param) so that both operands reference the same parameter node, producing a valid combined expression tree. Internal or nested lambda parameters that do not match the replaced parameter remain untouched.
These composable predicates underpin the Specification<T> pattern: a Specification<T> wraps an Expression<Func<T, bool>> as its Criteria property, and specification combinators (And, Or, Not) delegate to the corresponding ExpressionExtensions methods.
| Method | Returns | Description |
|---|---|---|
And(Expression<Func<T, bool>>) |
Expression<Func<T, bool>> |
Combines two predicate expressions with logical AND. |
Or(Expression<Func<T, bool>>) |
Expression<Func<T, bool>> |
Combines two predicate expressions with logical OR. |
Not() |
Expression<Func<T, bool>> |
Negates the predicate expression with logical NOT. |
using OnixLabs.Core.Linq;
using System;
using System.Linq.Expressions;
Expression<Func<int, bool>> isPositive = x => x > 0;
Expression<Func<int, bool>> isEven = x => x % 2 == 0;
Expression<Func<int, bool>> isPositiveAndEven = isPositive.And(isEven);
Expression<Func<int, bool>> isPositiveOrEven = isPositive.Or(isEven);
Expression<Func<int, bool>> isNotPositive = isPositive.Not();
Func<int, bool> predicate = isPositiveAndEven.Compile();
bool result = predicate(4); // Truepublic Expression<Func<T, bool>> And(Expression<Func<T, bool>> other)Combines two Expression<Func<T, bool>> instances into a single expression using the logical AND operator (AndAlso).
| Parameter | Type | Description |
|---|---|---|
other |
Expression<Func<T, bool>> |
The other (right-hand) expression to combine. |
| Type Parameter | Description |
|---|---|
T |
The underlying type of the (left-hand) expression. |
Returns — A new Expression<Func<T, bool>> that combines the two expressions using the logical AND operator.
public Expression<Func<T, bool>> Or(Expression<Func<T, bool>> other)Combines two Expression<Func<T, bool>> instances into a single expression using the logical OR operator (OrElse).
| Parameter | Type | Description |
|---|---|---|
other |
Expression<Func<T, bool>> |
The other (right-hand) expression to combine. |
| Type Parameter | Description |
|---|---|
T |
The underlying type of the (left-hand) expression. |
Returns — A new Expression<Func<T, bool>> that combines the two expressions using the logical OR operator.
public Expression<Func<T, bool>> Not()Negates the current Expression<Func<T, bool>> instance using the logical NOT operator.
| Type Parameter | Description |
|---|---|
T |
The underlying type of the expression. |
Returns — A new Expression<Func<T, bool>> that negates the current expression using the logical NOT operator.
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