Table of Contents

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

TResult

The type of the result.

Inheritance
PredicateBuilder<TResult>
Derived
Inherited Members

Methods

Build()

Builds the predicate.

public Predicate<Outcome<TResult>> Build()

Returns

Predicate<Outcome<TResult>>

An instance of predicate delegate.

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

TException

The type of the inner exception to handle.

Remarks

This method will also handle any exception found for InnerException of an Exception, or at any level of nesting within an AggregateException.

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

predicate Func<TException, bool>

The predicate function to use for handling the inner exception.

Returns

PredicateBuilder<TResult>

The same instance of the PredicateBuilder<TResult> for chaining.

Type Parameters

TException

The type of the inner exception to handle.

Remarks

This method will also handle any exception found for InnerException of an Exception, or at any level of nesting within an AggregateException.

Exceptions

ArgumentNullException

Thrown when the predicate is null.

HandleResult(Func<TResult, bool>)

Adds a predicate for handling results.

public PredicateBuilder<TResult> HandleResult(Func<TResult, bool> predicate)

Parameters

predicate Func<TResult, bool>

The predicate function to use for handling the result.

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

result TResult

The result value to handle.

comparer IEqualityComparer<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

TException

The 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

predicate Func<TException, bool>

The predicate function to use for handling the exception.

Returns

PredicateBuilder<TResult>

The same instance of the PredicateBuilder<TResult> for chaining.

Type Parameters

TException

The type of the exception to handle.

Exceptions

ArgumentNullException

Thrown when the predicate is null.