/// <summary> /// 反射实现深拷贝 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="to">要赋值对象</param> /// <param name="from">数据源对象</param> /// <param name="exceptProperties">指定不拷贝的属性</param> protected void Clone<T>(T to, T from, params string[] exceptProperties) where T : class { Func<PropertyInfo, bool> func = u => !u.GetMethod.IsVirtual;//不复制虚属性 if (exceptProperties != null) func = u => !(u.GetMethod.IsVirtual || exceptProperties.Contains(u.Name)); foreach (var property in from.GetType().GetProperties().Where(func)) property.SetValue(to, property.GetValue(from)); }
BeanUtils.copyProperties();
既然两个一样,那为什么要弄两个?
用AutoMap吧
automapper 走一发
emitmapper也很好