-
Notifications
You must be signed in to change notification settings - Fork 446
/
Copy pathDefaultApiActionInvokerProvider.cs
43 lines (41 loc) · 1.79 KB
/
DefaultApiActionInvokerProvider.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
37
38
39
40
41
42
43
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace WebApiClientCore.Implementations
{
/// <summary>
/// 表示ApiActionInvoker提供者
/// </summary>
public class DefaultApiActionInvokerProvider : IApiActionInvokerProvider
{
/// <summary>
/// 创建Action执行器
/// </summary>
/// <param name="actionDescriptor">Action描述</param>
/// <returns></returns>
public ApiActionInvoker CreateActionInvoker(ApiActionDescriptor actionDescriptor)
{
var actionInvoker = this.CreateDefaultActionInvoker(actionDescriptor);
if (actionDescriptor.Return.ReturnType.IsInheritFrom<Task>() == false)
{
if (actionInvoker is IITaskReturnConvertable conversable)
{
actionInvoker = conversable.ToITaskReturnActionInvoker();
}
}
return actionInvoker;
}
/// <summary>
/// 创建DefaultApiActionInvoker类型或其子类型的实例
/// </summary>
/// <param name="actionDescriptor">Action描述</param>
/// <returns></returns>
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(DefaultApiActionInvoker<>))]
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL3050", Justification = "类型已使用DynamicDependency来阻止被裁剪")]
protected virtual ApiActionInvoker CreateDefaultActionInvoker(ApiActionDescriptor actionDescriptor)
{
var resultType = actionDescriptor.Return.DataType.Type;
var invokerType = typeof(DefaultApiActionInvoker<>).MakeGenericType(resultType);
return invokerType.CreateInstance<ApiActionInvoker>(actionDescriptor);
}
}
}