namespace MasstransferCommon.Utils;
///
/// bean 工具类
///
public class BeanUtil
{
///
/// 实现Bean的属性复制
///
///
///
public static void CopyProperties(object source, object target)
{
var sourceProperties = source.GetType().GetProperties();
var targetProperties = target.GetType().GetProperties();
foreach (var sourceProperty in sourceProperties)
{
var targetProperty = Array.Find(targetProperties, p => p.Name == sourceProperty.Name &&
p.PropertyType == sourceProperty.PropertyType);
if (targetProperty != null && targetProperty.CanWrite)
targetProperty.SetValue(target, sourceProperty.GetValue(source));
}
}
public static T CopyProperties(object source)
{
var instance = Activator.CreateInstance();
CopyProperties(source, instance);
return instance;
}
public static List CopyProperties(IEnumerable