Class PredicateBuilder<TResult>
- Namespace
- Polly
- Assembly
- Polly.Core.dll
Defines a builder for creating predicates for TResult and Exception combinations.
public class PredicateBuilder<TResult>
Type Parameters
TResultThe type of the result.
- Inheritance
-
PredicateBuilder<TResult>
- Derived
- Inherited Members
Methods
Build()
Builds the predicate.
public Predicate<Outcome<TResult>> Build()
Returns
Remarks
The returned predicate will return true if any of the configured predicates return true. Please be aware of the performance penalty if you register too many predicates with this builder. In such case, it's better to create your own predicate manually as a delegate.
Exceptions
- InvalidOperationException
Thrown when no predicates were configured using this builder.
HandleInner<TException>()
Adds a predicate for handling inner exceptions of the specified type.
public PredicateBuilder<TResult> HandleInner<TException>() where TException : Exception
Returns
- PredicateBuilder<TResult>
The same instance of the PredicateBuilder<TResult> for chaining.
Type Parameters
TExceptionThe type of the inner exception to handle.
HandleInner<TException>(Func<TException, bool>)
Adds a predicate for handling inner exceptions of the specified type.
public PredicateBuilder<TResult> HandleInner<TException>(Func<TException, bool> predicate) where TException : Exception
Parameters
Returns
- PredicateBuilder<TResult>
The same instance of the PredicateBuilder<TResult> for chaining.
Type Parameters
TExceptionThe type of the inner exception to handle.
Exceptions
- ArgumentNullException
Thrown when the
predicateis null.
HandleResult(Func<TResult, bool>)
Adds a predicate for handling results.
public PredicateBuilder<TResult> HandleResult(Func<TResult, bool> predicate)
Parameters
Returns
- PredicateBuilder<TResult>
The same instance of the PredicateBuilder<TResult> for chaining.
HandleResult(TResult, IEqualityComparer<TResult>?)
Adds a predicate for handling results with a specific value.
public PredicateBuilder<TResult> HandleResult(TResult result, IEqualityComparer<TResult>? comparer = null)
Parameters
resultTResultThe result value to handle.
comparerIEqualityComparer<TResult>The comparer to use for comparing results. If null , the default comparer is used.
Returns
- PredicateBuilder<TResult>
The same instance of the PredicateBuilder<TResult> for chaining.
Handle<TException>()
Adds a predicate for handling exceptions of the specified type.
public PredicateBuilder<TResult> Handle<TException>() where TException : Exception
Returns
- PredicateBuilder<TResult>
The same instance of the PredicateBuilder<TResult> for chaining.
Type Parameters
TExceptionThe type of the exception to handle.
Handle<TException>(Func<TException, bool>)
Adds a predicate for handling exceptions of the specified type.
public PredicateBuilder<TResult> Handle<TException>(Func<TException, bool> predicate) where TException : Exception
Parameters
Returns
- PredicateBuilder<TResult>
The same instance of the PredicateBuilder<TResult> for chaining.
Type Parameters
TExceptionThe type of the exception to handle.
Exceptions
- ArgumentNullException
Thrown when the
predicateis null.