From a9a3f943efb083de8ed88b293897886b3ef612a2 Mon Sep 17 00:00:00 2001
From: helongyang <647556386@qq.com>
Date: 星期一, 11 八月 2025 17:37:09 +0800
Subject: [PATCH] 功能增添优化
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs | 44 ++++++++++++++++++++++++++++----------------
1 files changed, 28 insertions(+), 16 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs"
index 76e5aaf..b8bb9a9 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/ModelValidate.cs"
@@ -77,35 +77,49 @@
if (propertyAttribute == null) continue;
object? value = propertyInfo.GetValue(data, null);
+ if (value is IList)
+ {
+ IList list = (IList)value;
+ Type? t = list.GetType().GetGenericArguments().FirstOrDefault();
+ if (t != null && t.IsClass)
+ {
+ foreach (var item in list)
+ {
+ (bool, string, object?) result = ValidateModelData(item, t);
+ if (!result.Item1) return result;
+ }
+ }
+ }
+
if (propertyAttribute.NotNullAndEmpty)
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
- if (string.IsNullOrEmpty(value.ToString())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓虹┖瀛楃涓�", data);
+ if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})涓嶅彲涓簄ull", data);
+ if (string.IsNullOrEmpty(value.ToString())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})涓嶅彲涓虹┖瀛楃涓�", data);
}
if (propertyAttribute.MinValue > int.MinValue)
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
+ if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})涓嶅彲涓簄ull", data);
if (propertyAttribute.IsContainMinValue)
{
- if (Convert.ToInt32(value.ToString()) < propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戜笉鍙皬浜庛�恵propertyAttribute.MinValue}銆�", data);
+ if (Convert.ToInt32(value.ToString()) < propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})鐨勫�笺�恵value}銆戜笉鍙皬浜庛�恵propertyAttribute.MinValue}銆�", data);
}
else
{
- if (Convert.ToInt32(value.ToString()) <= propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戣澶т簬銆恵propertyAttribute.MinValue}銆�", data);
+ if (Convert.ToInt32(value.ToString()) <= propertyAttribute.MinValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})鐨勫�笺�恵value}銆戣澶т簬銆恵propertyAttribute.MinValue}銆�", data);
}
}
if (propertyAttribute.MaxValue < int.MaxValue)
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
+ if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})涓嶅彲涓簄ull", data);
if (propertyAttribute.IsContainMaxValue)
{
- if (Convert.ToInt32(value.ToString()) >= propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戜笉鍙ぇ浜庛�恵propertyAttribute.MaxValue}銆�", data);
+ if (Convert.ToInt32(value.ToString()) >= propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})鐨勫�笺�恵value}銆戜笉鍙ぇ浜庛�恵propertyAttribute.MaxValue}銆�", data);
}
else
{
- if (Convert.ToInt32(value.ToString()) > propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�笺�恵value}銆戣灏忎簬銆恵propertyAttribute.MaxValue}銆�", data);
+ if (Convert.ToInt32(value.ToString()) > propertyAttribute.MaxValue) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})鐨勫�笺�恵value}銆戣灏忎簬銆恵propertyAttribute.MaxValue}銆�", data);
}
}
@@ -184,25 +198,25 @@
if (propertyAttribute.Check != null && propertyAttribute.Check.Length > 0)
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
- if (propertyAttribute.Check.FirstOrDefault(x => x.ToString() == value.ToString()) == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}浣跨敤浜咰heck绾︽潫锛屼紶鍏ョ殑鍊间笉鍦▄propertyAttribute.Check.Serialize()}涓�", data);
+ if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})涓嶅彲涓簄ull", data);
+ if (propertyAttribute.Check.FirstOrDefault(x => x.ToString() == value.ToString()) == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})浣跨敤浜咰heck绾︽潫锛屼紶鍏ョ殑鍊间笉鍦▄propertyAttribute.Check.Serialize()}涓�", data);
}
if (!string.IsNullOrEmpty(propertyAttribute.StartWith) && !string.IsNullOrWhiteSpace(propertyAttribute.EndWith))
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
+ if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})涓嶅彲涓簄ull", data);
else
{
- if (value.ToString().StartsWith(propertyAttribute.StartWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}蹇呴』浠propertyAttribute.StartWith}寮�澶�", data);
+ if (value.ToString().StartsWith(propertyAttribute.StartWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})蹇呴』浠propertyAttribute.StartWith}寮�澶�", data);
}
}
if (!string.IsNullOrEmpty(propertyAttribute.EndWith) && !string.IsNullOrWhiteSpace(propertyAttribute.EndWith))
{
- if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}涓嶅彲涓簄ull", data);
+ if (value == null) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})涓嶅彲涓簄ull", data);
else
{
- if (value.ToString().EndsWith(propertyAttribute.EndWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}蹇呴』浠propertyAttribute.EndWith}缁撳熬", data);
+ if (value.ToString().EndsWith(propertyAttribute.EndWith.Trim())) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}({propertyInfo.Name})蹇呴』浠propertyAttribute.EndWith}缁撳熬", data);
}
}
@@ -213,8 +227,6 @@
if (value.ToString().Length < propertyAttribute.MinLength) return (false, $"{(string.IsNullOrEmpty(propertyAttribute.Description) ? propertyInfo.Name : propertyAttribute.Description)}鐨勫�煎皬浜庢渶灏忛暱搴︺�恵propertyAttribute.MinLength}銆戯紝鏁版嵁:{value}", data);
}
-
-
}
}
catch (Exception ex)
--
Gitblit v1.9.3