From de51ebf28c3f75822cb239316f084f2d5929277b Mon Sep 17 00:00:00 2001
From: xljiulang <366193849@qq.com>
Date: Wed, 5 Sep 2018 19:54:27 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0HandleForm=E6=96=B9=E6=B3=95?=
=?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=89=A9=E5=B1=95=E9=87=8D=E5=86=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../FormContentAttribute.cs | 20 ++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/WebApiClient/Attributes/ParameterAttributes/FormContentAttribute.cs b/WebApiClient/Attributes/ParameterAttributes/FormContentAttribute.cs
index 0f231205..7eb1b363 100644
--- a/WebApiClient/Attributes/ParameterAttributes/FormContentAttribute.cs
+++ b/WebApiClient/Attributes/ParameterAttributes/FormContentAttribute.cs
@@ -1,4 +1,5 @@
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
using WebApiClient.Contexts;
@@ -42,7 +43,7 @@ public FormContentAttribute(string datetimeFormat)
///
/// 上下文
/// 特性关联的参数
- protected override async Task SetHttpContentAsync(ApiActionContext context, ApiParameterDescriptor parameter)
+ protected sealed override async Task SetHttpContentAsync(ApiActionContext context, ApiParameterDescriptor parameter)
{
if (this.WillIgnore(parameter.Value) == true)
{
@@ -52,7 +53,20 @@ protected override async Task SetHttpContentAsync(ApiActionContext context, ApiP
var formatter = context.HttpApiConfig.KeyValueFormatter;
var options = context.HttpApiConfig.FormatOptions.CloneChange(this.DateTimeFormat);
var keyValues = formatter.Serialize(parameter, options);
- await context.RequestMessage.AddFormFieldAsync(keyValues).ConfigureAwait(false);
+ var form = this.HandleForm(keyValues);
+ await context.RequestMessage.AddFormFieldAsync(form).ConfigureAwait(false);
+ }
+
+ ///
+ /// 处理表单内容
+ /// 可以重写比方法
+ /// 实现字段排序、插入签名字段等
+ ///
+ /// 表单
+ ///
+ protected virtual IEnumerable> HandleForm(IEnumerable> form)
+ {
+ return form;
}
///