diff --git a/AutoMapProperty/AutoMapProperty.cs b/AutoMapProperty/AutoMapProperty.cs index 0d1b9a2..530dacf 100644 --- a/AutoMapProperty/AutoMapProperty.cs +++ b/AutoMapProperty/AutoMapProperty.cs @@ -645,8 +645,6 @@ namespace AutoMapProperty public static string? GeneratePropertyTo(List otherClasses, string Key, ITypeSymbol FromType, ITypeSymbol ToType, bool nullable = true) { - var sb = new StringBuilder(); - sb.Append(Key).Append(@" ="); var concreteToType = GetConcreteType(ToType); @@ -657,6 +655,15 @@ namespace AutoMapProperty if (concreteFromType.IsAbstract) return null; + var sb = new StringBuilder(); + + if (isArray) + { + sb.Append(Key).Append(".Any(); source."); + } + + sb.Append(Key).Append(@" ="); + if (isArray) { sb.Append("(").Append(FromType).Append(@")(this.").Append(Key).Append(" != null ? ");