using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace wcftest { public class ClassHelper { /// /// 实体互转 /// /// 新转换的实体 /// 要转换的实体 /// /// public static T RotationMapping(S s) { T target = Activator.CreateInstance(); 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; } } }