/// <summary>
/// 不同型別物件同名屬性賦值
/// </summary>
/// <typeparam name="S">源型別</typeparam>
/// <typeparam name="T">目標型別</typeparam>
/// <param name="s">源物件</param>
/// <param name="t">目標物件</param>
public static void AutoMapping<S, T>(S s, T t)
{
PropertyInfo[] pps = GetPropertyInfos(s.GetType());
Type target = t.GetType(); foreach (var pp in pps)
{
try
{
PropertyInfo targetPP = target.GetProperty(pp.Name);
object value = pp.GetValue(s, null); if (targetPP != null && value != null)
{
targetPP.SetValue(t, value, null);
}
}
catch (Exception ex)
{
throw ex;
}
}
}