OrSyntax
Fluent API for chaining exceptions that will be handled by a Policy.
using System;
using System.Collections.Generic;
namespace Polly
{
public static class OrSyntax
{
public static PolicyBuilder Or<TException>(this PolicyBuilder policyBuilder) where TException : Exception
{
ExceptionPredicate item = (Exception exception) => exception is TException;
((ICollection<ExceptionPredicate>)policyBuilder.ExceptionPredicates).Add(item);
return policyBuilder;
}
public static PolicyBuilder Or<TException>(this PolicyBuilder policyBuilder, Func<TException, bool> exceptionPredicate) where TException : Exception
{
ExceptionPredicate item = delegate(Exception exception) {
if (exception is TException)
return exceptionPredicate((TException)exception);
return false;
};
((ICollection<ExceptionPredicate>)policyBuilder.ExceptionPredicates).Add(item);
return policyBuilder;
}
}
}