/// <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); }
internal PolicyBuilder(ExceptionPredicate exceptionPredicate) { _exceptionPredicates = new List <ExceptionPredicate>() { exceptionPredicate }; }
/// <summary> /// Specifies the type of exception that this policy can handle with addition 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 static PolicyBuilder Handle <TException>(Func <TException, bool> exceptionPredicate) where TException : Exception { ExceptionPredicate predicate = exception => exception is TException && exceptionPredicate((TException)exception); return(new PolicyBuilder(predicate)); }
/// <summary> /// Specifies the type of exception that this policy can handle. /// </summary> /// <typeparam name="TException">The type of the exception to handle.</typeparam> /// <param name="policyBuilder">The current builder to chain off.</param> /// <returns>The PolicyBuilder instance.</returns> public static PolicyBuilder Or <TException>(this PolicyBuilder policyBuilder) where TException : Exception { ExceptionPredicate predicate = exception => exception is TException; policyBuilder.ExceptionPredicates.Add(predicate); return(policyBuilder); }
internal PolicyBuilder(ExceptionPredicate exceptionPredicate) { _exceptionPredicates = new List<ExceptionPredicate>() { exceptionPredicate }; }
/// <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); }
/// <summary> /// Specifies the type of exception that this policy can handle with addition filters on this exception type. /// </summary> /// <typeparam name="TException">The type of the exception.</typeparam> /// <param name="policyBuilder">The current builder to chain off.</param> /// <param name="exceptionPredicate">The exception predicate to filter the type of exception this policy can handle.</param> /// <returns>The PolicyBuilder instance.</returns> public static PolicyBuilder Or <TException>(this PolicyBuilder policyBuilder, Func <TException, bool> exceptionPredicate) where TException : Exception { ExceptionPredicate predicate = exception => exception is TException && exceptionPredicate((TException)exception); policyBuilder.ExceptionPredicates.Add(predicate); return(policyBuilder); }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionHandler" /> class. /// </summary> /// <param name="exceptionType">Type of the exception.</param> /// <param name="action">The action to execute.</param> /// <param name="filter">The exception filter.</param> /// <exception cref="ArgumentNullException">The <paramref name="exceptionType" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="action" /> is <c>null</c>.</exception> public ExceptionHandler(Type exceptionType, Action <Exception> action, ExceptionPredicate filter = null) { Argument.IsNotNull("exceptionType", exceptionType); Argument.IsNotNull("action", action); ExceptionType = exceptionType; _action = action; Filter = filter; }
/// <summary> /// Initializes a new instance of the <see cref="ExceptionHandler" /> class. /// </summary> /// <param name="exceptionType">Type of the exception.</param> /// <param name="action">The action to execute.</param> /// <param name="filter">The exception filter.</param> /// <exception cref="ArgumentNullException">The <paramref name="exceptionType" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="action" /> is <c>null</c>.</exception> public ExceptionHandler(Type exceptionType, Action<Exception> action, ExceptionPredicate filter = null) { Argument.IsNotNull("exceptionType", exceptionType); Argument.IsNotNull("action", action); ExceptionType = exceptionType; _action = action; Filter = filter; }
/// <summary> /// Registers a specific exception including the handler. /// </summary> /// <typeparam name="TException">The type of the exception.</typeparam> /// <param name="exceptionPredicate">The exception filter.</param> /// <param name="handler">The action to execute when the exception occurs.</param> /// <returns>The handler to use.</returns> /// <exception cref="ArgumentNullException">The <paramref name="handler"/> is <c>null</c>.</exception> /// <exception cref="Exception">A delegate callback throws an exception.</exception> public IExceptionHandler Register <TException>(Action <TException> handler, Func <TException, bool> exceptionPredicate = null) where TException : Exception { Argument.IsNotNull("handler", handler); var exceptionType = typeof(TException); ExceptionPredicate predicate = null; if (exceptionPredicate != null) { predicate = exception => exception is TException && exceptionPredicate((TException)exception); } var exceptionAction = new Action <Exception>(exception => handler((TException)exception)); var exceptionHandler = new ExceptionHandler(exceptionType, exceptionAction, predicate); return(Register(exceptionHandler)); }
internal void Add(ExceptionPredicate predicate) { _predicates = _predicates ?? new List <ExceptionPredicate>(); // The ?? pattern here is sufficient; only a deliberately contrived example would lead to the same PolicyBuilder instance being used in a multi-threaded way to define policies simultaneously on multiple threads. _predicates.Add(predicate); }
/// <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 static PolicyBuilder Handle <TException>() where TException : Exception { ExceptionPredicate predicate = exception => exception is TException; return(new PolicyBuilder(predicate)); }
internal PolicyBuilder(ExceptionPredicate exceptionPredicate) { ExceptionPredicates = new ExceptionPredicates(); ExceptionPredicates.Add(exceptionPredicate); }