Class Predicate
Provides extension methods for type Predicate<T> and predefined predicates.
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public static class Predicate
Methods
| Improve this Doc View SourceAnd<T>(Predicate<T>, Predicate<T>)
Returns a predicate which computes logical AND between results of two other predicates.
Declaration
public static Predicate<T> And<T>(this Predicate<T> left, Predicate<T> right)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | left | The first predicate acting as logical AND operand. |
Predicate<T> | right | The second predicate acting as logical AND operand. |
Returns
Type | Description |
---|---|
Predicate<T> | The predicate which computes logical AND between results of two other predicates. |
Type Parameters
Name | Description |
---|---|
T | Type of the predicate argument. |
AsConverter<T>(Predicate<T>)
Represents predicate as type Converter<TInput,TOutput>.
Declaration
public static Converter<T, bool> AsConverter<T>(this Predicate<T> predicate)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | predicate | A predicate to convert. |
Returns
Type | Description |
---|---|
Converter<T, Boolean> | A delegate of type Converter<TInput,TOutput> referencing the same method as original predicate. |
Type Parameters
Name | Description |
---|---|
T | Type of predicate argument. |
AsFunc<T>(Predicate<T>)
Represents predicate as type Func<T,TResult>.
Declaration
public static Func<T, bool> AsFunc<T>(this Predicate<T> predicate)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | predicate | A predicate to convert. |
Returns
Type | Description |
---|---|
Func<T, Boolean> | A delegate of type Func<T,TResult> referencing the same method as original predicate. |
Type Parameters
Name | Description |
---|---|
T | Type of predicate argument. |
AsValueFunc<T>(Predicate<T>, Boolean)
Converts predicate into ValueFunc<T, TResult>.
Declaration
public static ValueFunc<T, bool> AsValueFunc<T>(this Predicate<T> predicate, bool wrap = false)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | predicate | The predicate. |
Boolean | wrap | true to wrap |
Returns
Type | Description |
---|---|
ValueFunc<T, Boolean> | The value delegate representing predicate. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to check. |
False<T>()
Returns a predicate which always returns false.
Declaration
public static Predicate<T> False<T>()
Returns
Type | Description |
---|---|
Predicate<T> | A predicate which always returns false. |
Type Parameters
Name | Description |
---|---|
T | Type of predicate argument. |
Remarks
This method returns the same instance of predicate on every call.
HasValue<T>()
Returns predicate checking that input argument of value type is not null.
Declaration
public static Predicate<T?> HasValue<T>()
where T : struct
Returns
Type | Description |
---|---|
Predicate<Nullable<T>> | The predicate instance. |
Type Parameters
Name | Description |
---|---|
T | The type of the predicate argument. |
Remarks
This method returns the same instance of predicate on every call.
IsNotNull<T>()
Returns predicate checking that input argument is not null.
Declaration
public static Predicate<T> IsNotNull<T>()
where T : class
Returns
Type | Description |
---|---|
Predicate<T> | The predicate instance. |
Type Parameters
Name | Description |
---|---|
T | The type of the predicate argument. |
Remarks
This method returns the same instance of predicate on every call.
IsNull<T>()
Returns predicate implementing nullability check.
Declaration
public static Predicate<T> IsNull<T>()
where T : class
Returns
Type | Description |
---|---|
Predicate<T> | The predicate instance. |
Type Parameters
Name | Description |
---|---|
T | Type of predicate argument. |
Remarks
This method returns the same instance of predicate on every call.
Negate<T>(Predicate<T>)
Returns a predicate which negates evaluation result of the original predicate.
Declaration
public static Predicate<T> Negate<T>(this Predicate<T> predicate)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | predicate | The predicate to negate. |
Returns
Type | Description |
---|---|
Predicate<T> | The predicate which negates evaluation result of the original predicate. |
Type Parameters
Name | Description |
---|---|
T | Type of the predicate argument. |
Or<T>(Predicate<T>, Predicate<T>)
Returns a predicate which computes logical OR between results of two other predicates.
Declaration
public static Predicate<T> Or<T>(this Predicate<T> left, Predicate<T> right)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | left | The first predicate acting as logical OR operand. |
Predicate<T> | right | The second predicate acting as logical OR operand. |
Returns
Type | Description |
---|---|
Predicate<T> | The predicate which computes logical OR between results of two other predicates. |
Type Parameters
Name | Description |
---|---|
T | Type of the predicate argument. |
True<T>()
Returns a predicate which always returns true.
Declaration
public static Predicate<T> True<T>()
Returns
Type | Description |
---|---|
Predicate<T> | A predicate which always returns true. |
Type Parameters
Name | Description |
---|---|
T | Type of predicate argument. |
Remarks
This method returns the same instance of predicate on every call.
TryInvoke<T>(Predicate<T>, T)
Invokes predicate without throwing the exception.
Declaration
public static Result<bool> TryInvoke<T>(this Predicate<T> predicate, T obj)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | predicate | The predicate to invoke. |
T | obj | The object to compare against the criteria defined within the method represented by this delegate. |
Returns
Type | Description |
---|---|
Result<Boolean> | true if |
Type Parameters
Name | Description |
---|---|
T | The type of the object to compare. |
Xor<T>(Predicate<T>, Predicate<T>)
Returns a predicate which computes logical XOR between results of two other predicates.
Declaration
public static Predicate<T> Xor<T>(this Predicate<T> left, Predicate<T> right)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | left | The first predicate acting as logical XOR operand. |
Predicate<T> | right | The second predicate acting as logical XOR operand. |
Returns
Type | Description |
---|---|
Predicate<T> | The predicate which computes logical XOR between results of two other predicates. |
Type Parameters
Name | Description |
---|---|
T | Type of the predicate argument. |