alielie
2025-03-03 4c3eb7f334abb8129b57e86f2935d75d0b3070b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Reflection;
using System.Xml;
 
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));
            }
 
        }
    }
}