From 18f4ff408a84c23e60f09ad17ab78418d6131d7d Mon Sep 17 00:00:00 2001 From: Wvader <34067397+wvader@users.noreply.github.com> Date: Sat, 11 Dec 2021 14:09:11 +0000 Subject: [PATCH] x --- src/MapTo/Extensions/CommonSource.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/MapTo/Extensions/CommonSource.cs b/src/MapTo/Extensions/CommonSource.cs index 27ce9ff..aeda0b1 100644 --- a/src/MapTo/Extensions/CommonSource.cs +++ b/src/MapTo/Extensions/CommonSource.cs @@ -3,6 +3,7 @@ using static MapTo.Sources.Constants; using System; using System.Collections.Generic; using System.Text; +using System.Collections.Immutable; namespace MapTo.Extensions { @@ -64,12 +65,15 @@ namespace MapTo.Extensions var stringBuilder = new StringBuilder(); + var otherProperties = new List(); + foreach (var property in model.TypeProperties) { - if (!model.TypeProperties.IsMappedProperty(property)) + if (!model.TypeProperties.IsMappedProperty(property) || !model.SourceProperties.IsMappedProperty(property)) { stringBuilder.Append(", "); stringBuilder.Append($"{property.FullyQualifiedType} {property.SourcePropertyName.ToCamelCase()}"); + otherProperties.Add(property); } } @@ -78,7 +82,7 @@ namespace MapTo.Extensions builder .WriteLine($"public {model.TypeIdentifierName}({model.SourceType} {sourceClassParameterName}{readOnlyPropertiesArguments}){baseConstructor}") .WriteOpeningBracket() - .TryWriteProperties(model.SourceProperties, model.TypeProperties, sourceClassParameterName, mappingContextParameterName, false); + .TryWriteProperties(model.SourceProperties, otherProperties.ToArray().ToImmutableArray(), sourceClassParameterName, mappingContextParameterName, false); // End constructor declaration return builder.WriteClosingBracket(); @@ -137,7 +141,6 @@ namespace MapTo.Extensions foreach (var property in otherProperties) { - if(!properties.IsMappedProperty(property)) builder.WriteLine(property.MappedSourcePropertyTypeName is null ? $"{property.Name} = {property.SourcePropertyName.ToCamelCase()};" : "");