From bbafa4e9d8a43648f6e5e453f25fde35ea037a34 Mon Sep 17 00:00:00 2001 From: kevin <1985088337@qq.com> Date: Thu, 20 May 2021 10:41:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=A9=E5=B1=95=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OSS.Common/BasicMos/Resp/RespExtension.cs | 92 ++++++++++++----------- OSS.Common/OSS.Common.csproj | 6 +- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/OSS.Common/BasicMos/Resp/RespExtension.cs b/OSS.Common/BasicMos/Resp/RespExtension.cs index 06d0533..6ff150d 100644 --- a/OSS.Common/BasicMos/Resp/RespExtension.cs +++ b/OSS.Common/BasicMos/Resp/RespExtension.cs @@ -189,40 +189,6 @@ namespace OSS.Common.BasicMos.Resp return string.IsNullOrEmpty(errMsg) ? res : res.WithErrMsg(errMsg); } - /// - /// 处理响应转化 - /// - /// - /// - /// - /// 如果 tPara.IsSuccess()=false,且errMsg不为空,取errMsg,否则取 tPara.msg - /// - /// - /// - public static Resp WithResp(this Resp res, Resp tPara, - Func func,string errMsg = null) - { - res.data = func.Invoke(tPara.data); - return res.WithResp(tPara, errMsg); - } - - /// - /// 处理响应转化 - /// - /// - /// - /// - /// - /// - /// 不成功时的消息内容,如果为空,消息内容取 tPara.msg - /// - public static ListResp WithResp(this ListResp res, ListResp tPara, - Func func, string errMsg = null) - { - res.data = tPara.data?.Select(func).ToList(); - return res.WithResp(tPara, errMsg); - } - /// /// 处理响应转化 /// @@ -238,29 +204,65 @@ namespace OSS.Common.BasicMos.Resp return string.IsNullOrEmpty(errMsg) ? res : res.WithErrMsg(errMsg); } + #region 附带 data 转化处理 + /// /// 处理响应转化 /// /// /// - /// - /// 是否检查参数 data 为空 + /// + /// 如果 tPara.IsSuccess()=false,且errMsg不为空,取errMsg,否则取 tPara.msg + /// 调用方法(convertFunc)之前是否检查数据是否为空 /// /// /// - [Obsolete] public static Resp WithResp(this Resp res, Resp tPara, - Func func, bool isNullCheck = true) + Func convertFunc, string errMsg, bool isNullCheck = true) { - WithResp(res, tPara.sys_ret, tPara.ret, tPara.msg); - - if (isNullCheck && tPara.data == null) - return res ; - - res.data = func.Invoke(tPara.data); - return res; + if ((isNullCheck && tPara.data != null) + || !isNullCheck) + { + res.data = convertFunc.Invoke(tPara.data); + } + return res.WithResp(tPara, errMsg); } + /// + /// 处理响应转化 + /// + /// + /// + /// + /// 调用方法(convertFunc)之前是否检查数据是否为空 + /// + /// + /// + public static Resp WithResp(this Resp res, Resp tPara, + Func convertFunc, bool isNullCheck=true) + { + return res.WithResp(tPara, convertFunc, null, isNullCheck); + } + + /// + /// 处理响应转化 + /// + /// + /// + /// + /// + /// + /// 不成功时的消息内容,如果为空,消息内容取 tPara.msg + /// + public static ListResp WithResp(this ListResp res, ListResp tPara, + Func convertFunc, string errMsg = null) + { + res.data = tPara.data?.Select(convertFunc).ToList(); + return res.WithResp(tPara, errMsg); + } + + #endregion + #endregion /// diff --git a/OSS.Common/OSS.Common.csproj b/OSS.Common/OSS.Common.csproj index a01a92e..ccbed46 100644 --- a/OSS.Common/OSS.Common.csproj +++ b/OSS.Common/OSS.Common.csproj @@ -3,7 +3,7 @@ netstandard2.0 False - 2.3.3 + 2.3.3.2 false OSSCore OSSCore @@ -14,8 +14,8 @@ https://github.com/KevinWG/OSS.Common 添加结果处理扩展函数 - 2.3.3.0 - 2.3.3.0 + 2.3.3.2 + 2.3.3.2 https://github.com/KevinWG/OSS.Common/blob/master/LICENSE