From 971e03ccbe5124d4761f56e71025453d1d4742bc Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 17 九月 2025 14:17:08 +0800 Subject: [PATCH] 111 --- entity/Base/RequestInfo.cs | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) diff --git a/entity/Base/RequestInfo.cs b/entity/Base/RequestInfo.cs index 81c8c9b..08a12ba 100644 --- a/entity/Base/RequestInfo.cs +++ b/entity/Base/RequestInfo.cs @@ -1,11 +1,10 @@ -锘縰sing System.Dynamic; - -namespace NewPdaSqlServer.entity.Base; +锘縰sing Microsoft.AspNetCore.Http; +using System.Dynamic; public class RequestInfo : DynamicObject { - private readonly ExpandoObject _data = new(); private readonly IHttpContextAccessor _httpContextAccessor; + private readonly ExpandoObject _data = new ExpandoObject(); public RequestInfo(IHttpContextAccessor httpContextAccessor) { @@ -24,9 +23,8 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) { - var name = binder.Name; - return ((IDictionary<string, object>)_data).TryGetValue(name, - out result); + string name = binder.Name; + return ((IDictionary<string, object>)_data).TryGetValue(name, out result); } public override bool TrySetMember(SetMemberBinder binder, object value) @@ -38,8 +36,10 @@ 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,8 +52,12 @@ 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