schangxiang@126.com
2025-09-17 9d9c5593801ed3356f976ac499a61a6673bd67ca
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
 
namespace iWareCommon.Utils
{
    public class ClassHelper
    {
        /// <summary>
        /// 实体互转
        /// </summary>
        /// <typeparam name="T">新转换的实体</typeparam>
        /// <typeparam name="S">要转换的实体</typeparam>
        /// <param name="s"></param>
        /// <returns></returns>
        public static T RotationMapping<T, S>(S s)
        {
            T target = Activator.CreateInstance<T>();
            var originalObj = s.GetType();
            var targetObj = typeof(T);
            foreach (PropertyInfo original in originalObj.GetProperties())
            {
                foreach (PropertyInfo t in targetObj.GetProperties())
                {
                    if (t.Name == original.Name)
                    {
                        t.SetValue(target, original.GetValue(s, null), null);
                    }
                }
            }
            return target;
        }
 
      
        
    }
}