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;
|
}
|
|
|
|
}
|
}
|