From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点
---
HMI.Core/Util/BeanUtil.cs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/HMI.Core/Util/BeanUtil.cs b/HMI.Core/Util/BeanUtil.cs
new file mode 100644
index 0000000..3e7e5ef
--- /dev/null
+++ b/HMI.Core/Util/BeanUtil.cs
@@ -0,0 +1,49 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Data;
+using System.Reflection;
+
+namespace HMI.Core.Util
+{
+ public class BeanUtil
+ {
+ public static void Copy<S, T>(S source, T target)
+ {
+ Type sourceType = typeof(S);
+ Type targetType = typeof(T);
+ PropertyInfo[] fieldArray = targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ foreach (PropertyInfo field in fieldArray)
+ {
+ string fileName = field.Name;
+ PropertyInfo sourceField = sourceType.GetProperty(fileName);
+ if (sourceField == null) continue;
+ field.SetValue(target, sourceField.GetValue(source));
+ }
+
+ }
+
+ 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