29 lines
881 B
C#
29 lines
881 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Helpers
|
|
{
|
|
public static class CopyModelHelper
|
|
{
|
|
public static void CopyPublicProperties<TSource, TDestination>(TSource src, TDestination dest)
|
|
{
|
|
if (src == null || dest == null) return;
|
|
|
|
var srcProps = typeof(TSource)
|
|
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
|
.Where(p => p.CanRead);
|
|
|
|
foreach (var sp in srcProps)
|
|
{
|
|
var dp = typeof(TDestination).GetProperty(sp.Name, BindingFlags.Public | BindingFlags.Instance);
|
|
if (dp == null || !dp.CanWrite) continue;
|
|
dp.SetValue(dest, sp.GetValue(src));
|
|
}
|
|
}
|
|
}
|
|
}
|