/// <summary>
/// <typeparam name="T">源对象</typeparam>
/// <typeparam name="M">目标对象</typeparam>
/// <param name="Sobj"></param>
/// <param name="Eobj"></param>
/// <param name="except"></param>
/// </summary>
protected void SetObjToEntity<T, M>(T Sobj, M Eobj, string except)
{
foreach (PropertyInfo proM in typeof(M).GetProperties()) {
if (except.IndexOf(proM.Name) >= 0) {
continue;
}
foreach (PropertyInfo proT in typeof(T).GetProperties()) {
if (proM.Name == proT.Name) {
if (proT.GetValue(Sobj, null) != null) {
if (proM.PropertyType == typeof(System.Nullable<double>) || proM.PropertyType == typeof(System.Double)) {
proM.SetValue(Eobj, Convert.ToDouble(proT.GetValue(Sobj, null)), null);
}
else if (proM.PropertyType == typeof(System.Nullable<Int16>)) {
proM.SetValue(Eobj, Convert.ToInt16(proT.GetValue(Sobj, null)), null);
}
else if (proM.PropertyType == typeof(System.Byte)) {
proM.SetValue(Eobj, Convert.ToByte(proT.GetValue(Sobj, null)), null);
}
else if (proM.PropertyType == typeof(System.Decimal)) {
proM.SetValue(Eobj, Convert.ToDecimal(proT.GetValue(Sobj, null)), null);
}
else if (proT.PropertyType == typeof(System.Char)) {
proM.SetValue(Eobj, Convert.ToString(proT.GetValue(Sobj, null)), null);
}
else if (proM.PropertyType == typeof(System.Char)) {
proM.SetValue(Eobj, Convert.ToChar(proT.GetValue(Sobj, null)), null);
}
else {
proM.SetValue(Eobj, proT.GetValue(Sobj, null), null);
} // 可以添加更多的数据类型 } else { proM.SetValue(Eobj, null, null); }
}
}
}
}
}