From e865a0535a001d584771b86e0c07b9372132acff Mon Sep 17 00:00:00 2001 From: Loretta Date: Sun, 12 Oct 2025 07:47:39 +0200 Subject: [PATCH] CopyPublicValueTypeProperties fixes --- AyCode.Core/Extensions/PropertyHelper.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/AyCode.Core/Extensions/PropertyHelper.cs b/AyCode.Core/Extensions/PropertyHelper.cs index a2078a4..d1cf1dc 100644 --- a/AyCode.Core/Extensions/PropertyHelper.cs +++ b/AyCode.Core/Extensions/PropertyHelper.cs @@ -5,16 +5,17 @@ namespace AyCode.Core.Extensions; public static class PropertyHelper { - public static TDestination CopyPublicProperties(TSource src, TDestination dest) + public static TDestination CopyPublicValueTypeProperties(TSource src, TDestination dest) { if (src == null || dest == null) return dest; - var srcProps = typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead); + var srcProps = typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead && !typeof(IEnumerable).IsAssignableFrom(p.PropertyType)); foreach (var sp in srcProps) { var dp = typeof(TDestination).GetProperty(sp.Name, BindingFlags.Public | BindingFlags.Instance); - if (dp == null || !dp.CanWrite || dp is IEnumerable) continue; + if (dp == null || !dp.CanWrite || typeof(IEnumerable).IsAssignableFrom(dp.PropertyType)) //dp.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + continue; dp.SetValue(dest, sp.GetValue(src)); }