forked from dotnetcore/WebApiClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIHandleTask.cs
36 lines (33 loc) · 1.28 KB
/
IHandleTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Threading.Tasks;
namespace WebApiClientCore
{
/// <summary>
/// 定义异常处理的行为
/// </summary>
/// <typeparam name="TResult"></typeparam>
public interface IHandleTask<TResult> : ITask<TResult>
{
/// <summary>
/// 当捕获到异常时返回指定结果
/// </summary>
/// <typeparam name="TException"></typeparam>
/// <param name="func">获取结果</param>
/// <returns></returns>
IHandleTask<TResult> WhenCatch<TException>(Func<TResult> func) where TException : Exception;
/// <summary>
/// 当捕获到异常时返回指定结果
/// </summary>
/// <typeparam name="TException"></typeparam>
/// <param name="func">获取结果</param>
/// <returns></returns>
IHandleTask<TResult> WhenCatch<TException>(Func<TException, TResult> func) where TException : Exception;
/// <summary>
/// 当捕获到异常时返回指定结果
/// </summary>
/// <typeparam name="TException"></typeparam>
/// <param name="func">获取结果</param>
/// <returns></returns>
IHandleTask<TResult> WhenCatchAsync<TException>(Func<TException, Task<TResult>> func) where TException : Exception;
}
}