From 0aa54059b26e6641196e9953490dd18616e916e3 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 10 九月 2025 17:26:47 +0800 Subject: [PATCH] 精简修正代码 --- entity/Base/RequestInfo.cs | 22 +++++++++------------- 1 files changed, 9 insertions(+), 13 deletions(-) diff --git a/entity/Base/RequestInfo.cs b/entity/Base/RequestInfo.cs index 08a12ba..81c8c9b 100644 --- a/entity/Base/RequestInfo.cs +++ b/entity/Base/RequestInfo.cs @@ -1,10 +1,11 @@ -锘縰sing Microsoft.AspNetCore.Http; -using System.Dynamic; +锘縰sing System.Dynamic; + +namespace NewPdaSqlServer.entity.Base; public class RequestInfo : DynamicObject { + private readonly ExpandoObject _data = new(); private readonly IHttpContextAccessor _httpContextAccessor; - private readonly ExpandoObject _data = new ExpandoObject(); public RequestInfo(IHttpContextAccessor httpContextAccessor) { @@ -23,8 +24,9 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) { - string name = binder.Name; - return ((IDictionary<string, object>)_data).TryGetValue(name, out result); + var name = binder.Name; + return ((IDictionary<string, object>)_data).TryGetValue(name, + out result); } public override bool TrySetMember(SetMemberBinder binder, object value) @@ -36,10 +38,8 @@ public string GetHeaderValue(string key) { var httpContext = _httpContextAccessor.HttpContext; - if (httpContext?.Request.Headers.TryGetValue(key, out var value) == true) - { - return value.ToString(); - } + if (httpContext?.Request.Headers.TryGetValue(key, out var value) == + true) return value.ToString(); return null; } @@ -52,12 +52,8 @@ public void ValidateRequired(params string[] requiredFields) { foreach (var field in requiredFields) - { if (!((IDictionary<string, object>)_data).ContainsKey(field) || ((IDictionary<string, object>)_data)[field] == null) - { throw new ArgumentException($"璇锋眰澶翠腑缂哄皯蹇呴渶鐨� {field} 鍙傛暟"); - } - } } } \ No newline at end of file -- Gitblit v1.9.3