/// <summary>
/// 反射两个类替换 (当要修改的类中有null值是用历史类里面的值)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="sobj">要修改的类</param>
/// <param name="gobj">历史类</param>
public static void FieldReplacement<T>(T sobj, T gobj)
{
foreach (var property in sobj.GetType().GetProperties())
{
if (property.Name != null)
{
if (property.GetValue(sobj, null) == null)
{
property.SetValue(sobj, property.GetValue(gobj, null), null);
}
}
}
/// 反射两个类替换 (当要修改的类中有null值是用历史类里面的值)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="sobj">要修改的类</param>
/// <param name="gobj">历史类</param>
public static void FieldReplacement<T>(T sobj, T gobj)
{
foreach (var property in sobj.GetType().GetProperties())
{
if (property.Name != null)
{
if (property.GetValue(sobj, null) == null)
{
property.SetValue(sobj, property.GetValue(gobj, null), null);
}
}
}
}
//判断类型 if (property.PropertyType == typeof(int))