From b5bc0d6eb2d2e55ea830a1b286252b9754cbf8e9 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期三, 21 八月 2024 11:21:04 +0800
Subject: [PATCH] 更新主从表添加、修改、删除时对从表的对应操作

---
 WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/ObjectExtension.cs |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/ObjectExtension.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/ObjectExtension.cs
index 7064e2c..03e8283 100644
--- a/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/ObjectExtension.cs
+++ b/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/ObjectExtension.cs
@@ -9,18 +9,14 @@
 {
     public static class ObjectExtension
     {
-        public static IEnumerable<T> DicToIEnumerable<T>(this List<Dictionary<string, object>> dicList)
+        public static List<T> DicToIEnumerable<T>(this List<Dictionary<string, object>> dicList)
         {
+            List<T> list = new List<T>();
             foreach (Dictionary<string, object> dic in dicList)
             {
-                T model = Activator.CreateInstance<T>();
-                foreach (PropertyInfo property in model.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
-                {
-                    if (!dic.TryGetValue(property.Name, out object value)) continue;
-                    property.SetValue(model, value?.ToString().ChangeType(property.PropertyType), null);
-                }
-                yield return model;
+                list.Add(dic.DicToModel<T>());
             }
+            return list;
         }
 
         public static T DicToModel<T>(this Dictionary<string, object> dic)
@@ -30,7 +26,7 @@
             foreach (var property in propertyInfos)
             {
                 object value = null;
-                if (!dic.TryGetValue(property.Name, out value)) 
+                if (!dic.TryGetValue(property.Name, out value))
                 {
                     if (!dic.TryGetValue(property.Name.FirstLetterToUpper(), out value))
                     {

--
Gitblit v1.9.3