From daea1a90c2fa1b5cc2f52e62be15bd95cc4155f6 Mon Sep 17 00:00:00 2001
From: Tiandele <tiandele@hnkhzn.com>
Date: 星期五, 20 三月 2026 17:16:04 +0800
Subject: [PATCH] 优化手动锁车逻辑
---
项目代码/WMS/WMSServer/WIDESEA_Core/Helper/ObjectExtension.cs | 59 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 45 insertions(+), 14 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_Core/Helper/ObjectExtension.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_Core/Helper/ObjectExtension.cs"
index 1707c35..006dda8 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_Core/Helper/ObjectExtension.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServer/WIDESEA_Core/Helper/ObjectExtension.cs"
@@ -1,5 +1,6 @@
锘縰sing Microsoft.Extensions.Primitives;
using Microsoft.IdentityModel.Tokens;
+using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -23,26 +24,56 @@
public static T DicToModel<T>(this Dictionary<string, object> dic)
{
- T model = Activator.CreateInstance<T>();
- PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance);
- foreach (var property in propertyInfos)
+ #region
+ //T model = Activator.CreateInstance<T>();
+ //PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance);
+ //foreach (var property in propertyInfos)
+ //{
+ // object value = null;
+ // if (!dic.TryGetValue(property.Name, out value))
+ // {
+ // if (!dic.TryGetValue(property.Name.FirstLetterToUpper(), out value))
+ // {
+ // if (!dic.TryGetValue(property.Name.FirstLetterToLower(), out value))
+ // {
+ // continue;
+ // }
+ // }
+ // }
+ // // 妫�鏌ユ槸鍚︿负绌哄瓧绗︿覆
+ // if (!string.IsNullOrEmpty(value?.ToString()))
+ // {
+ // // 灏嗗�艰浆鎹负灞炴�х殑绫诲瀷骞惰缃睘鎬у��
+ // property.SetValue(model, value.ChangeType(property.PropertyType));
+ // }
+ //}
+ //return model;
+ #endregion
+
+ T? model = Activator.CreateInstance<T>();
+ try
{
- object value = null;
- if (!dic.TryGetValue(property.Name, out value))
+ model = JsonConvert.DeserializeObject<T>(dic.Serialize());
+ }
+ catch { }
+ if (model == null)
+ {
+ PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance);
+ foreach (var property in propertyInfos)
{
- if (!dic.TryGetValue(property.Name.FirstLetterToUpper(), out value))
+ object value = null;
+ if (!dic.TryGetValue(property.Name, out value))
{
- if (!dic.TryGetValue(property.Name.FirstLetterToLower(), out value))
+ if (!dic.TryGetValue(property.Name.FirstLetterToUpper(), out value))
{
- continue;
+ if (!dic.TryGetValue(property.Name.FirstLetterToLower(), out value))
+ {
+ continue;
+ }
}
}
- }
- // 妫�鏌ユ槸鍚︿负绌哄瓧绗︿覆
- if (!string.IsNullOrEmpty(value?.ToString()))
- {
- // 灏嗗�艰浆鎹负灞炴�х殑绫诲瀷骞惰缃睘鎬у��
- property.SetValue(model, value.ChangeType(property.PropertyType));
+ ;
+ property.SetValue(model, value?.ToString().ChangeType(property.PropertyType));
}
}
return model;
--
Gitblit v1.9.3