| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ips.Library.Basic
- {
- public static class CommonExceptionExtensions
- {
- public static void HandleCancelEx(this Exception source, Action<Exception> handleAct, Action<OperationCanceledException> opCancelAct = null)
- {
- if (source == null) return;
- var aggex = source as AggregateException;
- if (aggex != null)
- {
- aggex.Flatten().Handle(ex =>
- {
- HandleEx(ex, handleAct, opCancelAct);
- return true;
- });
- }
- else
- {
- HandleEx(source, handleAct, opCancelAct);
- }
- }
- private static void HandleEx(Exception ex, Action<Exception> handleAct, Action<OperationCanceledException> opCancelAct)
- {
- if (ex is OperationCanceledException)
- {
- opCancelAct?.Invoke((OperationCanceledException)ex);
- }
- else
- {
- handleAct(ex);
- }
- }
- }
- }
|