コード例 #1
0
        /// <summary>
        /// Specifies the type of exception that this policy can handle.
        /// </summary>
        /// <typeparam name="TException">The type of the exception to handle.</typeparam>
        /// <returns>The PolicyBuilder instance.</returns>
        public PolicyBuilder Or <TException>() where TException : Exception
        {
            ExceptionPredicate predicate = exception => exception is TException;

            ExceptionPredicates.Add(predicate);
            return(this);
        }
コード例 #2
0
        /// <summary>
        /// Specifies the type of exception that this policy can handle with additional filters on this exception type.
        /// </summary>
        /// <typeparam name="TException">The type of the exception.</typeparam>
        /// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param>
        /// <returns>The PolicyBuilder instance.</returns>
        public PolicyBuilder Or <TException>(Func <TException, bool> exceptionPredicate) where TException : Exception
        {
            ExceptionPredicate predicate = exception => exception is TException &&
                                           exceptionPredicate((TException)exception);

            ExceptionPredicates.Add(predicate);
            return(this);
        }
コード例 #3
0
        internal static ExceptionType GetExceptionType(ExceptionPredicates exceptionPredicates, Exception exception)
        {
            bool isExceptionTypeHandledByThisPolicy = exceptionPredicates.FirstMatchOrDefault(exception) != null;

            return(isExceptionTypeHandledByThisPolicy
                ? ExceptionType.HandledByThisPolicy
                : ExceptionType.Unhandled);
        }
コード例 #4
0
 internal PolicyBuilder(ExceptionPredicate exceptionPredicate)
 {
     ExceptionPredicates = new ExceptionPredicates();
     ExceptionPredicates.Add(exceptionPredicate);
 }
コード例 #5
0
 /// <summary>
 /// Specifies the type of exception that this policy can handle if found as an InnerException of a regular <see cref="Exception"/>, or at any level of nesting within an <see cref="AggregateException"/>.
 /// </summary>
 /// <typeparam name="TException">The type of the exception to handle.</typeparam>
 /// <returns>The PolicyBuilder instance, for fluent chaining.</returns>
 public PolicyBuilder OrInner <TException>() where TException : Exception
 {
     ExceptionPredicates.Add((HandleInner(ex => ex is TException)));
     return(this);
 }
コード例 #6
0
 /// <summary>
 /// Specifies the type of exception that this policy can handle.
 /// </summary>
 /// <typeparam name="TException">The type of the exception to handle.</typeparam>
 /// <returns>The PolicyBuilder instance.</returns>
 public PolicyBuilder Or <TException>() where TException : Exception
 {
     ExceptionPredicates.Add(exception => exception is TException ? exception : null);
     return(this);
 }
コード例 #7
0
 /// <summary>
 /// Constructs a new instance of a derived type of <see cref="PolicyBase"/> with the passed <paramref name="exceptionPredicates"/>.
 /// </summary>
 /// <param name="exceptionPredicates">Predicates indicating which exceptions the policy should handle. </param>
 internal PolicyBase(ExceptionPredicates exceptionPredicates)
 => ExceptionPredicates = exceptionPredicates ?? ExceptionPredicates.None;