public static TTarget MapColumns<TSource, TTarget>(TSource source, TTarget target)
where TSource : class, new()
where TTarget : class, new()
{
if (source == null || target == null)
{
return default;
}
var sourceType = typeof(TSource);
var targetType = typeof(TTarget);
var targetTypeProps = targetType.GetProperties();
PropertyInfo cur = default;
foreach (var item in sourceType.GetProperties())
{
cur = targetTypeProps.FirstOrDefault(a => a.Name == item.Name);
if (cur == null) { continue; }
cur.SetValue(target, cur.GetValue(source));
}
return target;
}