Skip to content

Commit 50a0865

Browse files
committed
增加Result属性
1 parent bb8a830 commit 50a0865

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

WebApiClient/Contexts/ApiActionContext.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ public Tags Tags
4949
public HttpResponseMessage ResponseMessage { get; internal set; }
5050

5151
/// <summary>
52-
/// 获取执行产生的异常
52+
/// 获取调用Api得到的结果
53+
/// </summary>
54+
public object Result { get; internal set; }
55+
56+
/// <summary>
57+
/// 获取调用Api产生的异常
5358
/// </summary>
5459
public Exception Exception { get; internal set; }
5560
}

WebApiClient/Internal/Tasks/ApiTask.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ private async Task<TResult> RequestAsync()
130130

131131
try
132132
{
133-
var result = await this.RequestAsync(context);
134-
return (TResult)result;
133+
await this.RequestAsync(context);
134+
return (TResult)context.Result;
135135
}
136136
catch (Exception ex)
137137
{
@@ -147,7 +147,7 @@ private async Task<TResult> RequestAsync()
147147
/// </summary>
148148
/// <param name="context">上下文</param>
149149
/// <returns></returns>
150-
private async Task<object> RequestAsync(ApiActionContext context)
150+
private async Task RequestAsync(ApiActionContext context)
151151
{
152152
var apiAction = context.ApiActionDescriptor;
153153
var globalFilters = context.HttpApiConfig.GlobalFilters;
@@ -177,7 +177,7 @@ private async Task<object> RequestAsync(ApiActionContext context)
177177

178178
var client = context.HttpApiConfig.HttpClient;
179179
context.ResponseMessage = await client.SendAsync(context.RequestMessage);
180-
var result = await apiAction.Return.Attribute.GetTaskResult(context);
180+
context.Result = await apiAction.Return.Attribute.GetTaskResult(context);
181181

182182
foreach (var filter in globalFilters)
183183
{
@@ -188,7 +188,6 @@ private async Task<object> RequestAsync(ApiActionContext context)
188188
{
189189
await filter.OnEndRequestAsync(context);
190190
}
191-
return result;
192191
}
193192

194193

0 commit comments

Comments
 (0)