From 0940f31b7eba1cf6b6a8c1fca72d97cf686e79f2 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 04 七月 2025 10:43:00 +0800
Subject: [PATCH] 优化插件,完善TreeListView

---
 HMI.Core/Util/BeanUtil.cs |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/HMI.Core/Util/BeanUtil.cs b/HMI.Core/Util/BeanUtil.cs
index 1ac90f8..3e7e5ef 100644
--- a/HMI.Core/Util/BeanUtil.cs
+++ b/HMI.Core/Util/BeanUtil.cs
@@ -1,6 +1,7 @@
 锘縰sing System;
+using System.Collections.Generic;
+using System.Data;
 using System.Reflection;
-using System.Xml;
 
 namespace HMI.Core.Util
 {
@@ -20,5 +21,29 @@
             }
 
         }
+
+        public static List<T> ReadBeanFromDataTable<T>(DataTable table)
+        {
+            if (table == null || table.Rows.Count <= 0) return new List<T>();
+
+            List<T> list = new List<T>();
+            foreach (DataRow row in table.Rows)
+            {
+                T bean = Activator.CreateInstance<T>();
+                foreach (var prop in typeof(T).GetProperties())
+                {
+                    if (table.Columns.Contains(prop.Name))
+                    {
+                        var value = row[prop.Name];
+                        if (value != DBNull.Value)
+                        {
+                            prop.SetValue(bean, Convert.ChangeType(value, prop.PropertyType));
+                        }
+                    }
+                }
+                list.Add(bean);
+            }
+            return list;
+        }
     }
 }

--
Gitblit v1.9.1