chr
2025-01-03 31a636e735a0addc56e4f4527f500b7aa0874eb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Reflection;
 
namespace PdmSwPlugin.Common.Util
{
    public static class BeanUtil
    {
        public static FieldInfo[] GetTypeFields(Type type, BindingFlags bindingAttr) {
            FieldInfo[] fields = type.GetFields(bindingAttr);
            return fields;
        }
        
        public static PropertyInfo[] GetTypeProperties(Type type, BindingFlags bindingAttr) {
            PropertyInfo[] fields = type.GetProperties(bindingAttr);
            return fields;
        }
 
        public static void CopyPropertyIgnoreNull<T>(T source, T target)
        {
            if (source == null)
            {
                return;
            }
            Type type = source.GetType();
            if (source is string || type.IsValueType)
            {
                return;
            }
 
            FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
            foreach (FieldInfo field in fields)
            {
                object value = field.GetValue(source);
                if (value != null)
                {
                    field.SetValue(target, field.GetValue(source));
                }
 
            }
            return;
        }
 
    }
}