Skip to content

Commit c6b1b22

Browse files
committed
2 parents 3004fb7 + de51ebf commit c6b1b22

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

WebApiClient/Attributes/ParameterAttributes/FormContentAttribute.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.Collections.Generic;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using WebApiClient.Contexts;
45

@@ -42,7 +43,7 @@ public FormContentAttribute(string datetimeFormat)
4243
/// </summary>
4344
/// <param name="context">上下文</param>
4445
/// <param name="parameter">特性关联的参数</param>
45-
protected override async Task SetHttpContentAsync(ApiActionContext context, ApiParameterDescriptor parameter)
46+
protected sealed override async Task SetHttpContentAsync(ApiActionContext context, ApiParameterDescriptor parameter)
4647
{
4748
if (this.WillIgnore(parameter.Value) == true)
4849
{
@@ -52,7 +53,20 @@ protected override async Task SetHttpContentAsync(ApiActionContext context, ApiP
5253
var formatter = context.HttpApiConfig.KeyValueFormatter;
5354
var options = context.HttpApiConfig.FormatOptions.CloneChange(this.DateTimeFormat);
5455
var keyValues = formatter.Serialize(parameter, options);
55-
await context.RequestMessage.AddFormFieldAsync(keyValues).ConfigureAwait(false);
56+
var form = this.HandleForm(keyValues);
57+
await context.RequestMessage.AddFormFieldAsync(form).ConfigureAwait(false);
58+
}
59+
60+
/// <summary>
61+
/// 处理表单内容
62+
/// 可以重写比方法
63+
/// 实现字段排序、插入签名字段等
64+
/// </summary>
65+
/// <param name="form">表单</param>
66+
/// <returns></returns>
67+
protected virtual IEnumerable<KeyValuePair<string, string>> HandleForm(IEnumerable<KeyValuePair<string, string>> form)
68+
{
69+
return form;
5670
}
5771

5872
/// <summary>

0 commit comments

Comments
 (0)