From 542cdb05f87d4a1bdfd13bb44d745ccb6f412b8d Mon Sep 17 00:00:00 2001 From: Mohammadreza Taikandi Date: Sun, 7 Feb 2021 10:55:08 +0000 Subject: [PATCH] Use extension method to map the nested objects. --- src/MapTo/Sources/MapClassSource.cs | 4 ++-- test/MapTo.Tests/MapToTests.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MapTo/Sources/MapClassSource.cs b/src/MapTo/Sources/MapClassSource.cs index f7e2f5b..10229b7 100644 --- a/src/MapTo/Sources/MapClassSource.cs +++ b/src/MapTo/Sources/MapClassSource.cs @@ -71,8 +71,8 @@ namespace MapTo.Sources if (property.TypeConverter is null) { builder.WriteLine(property.MappedSourcePropertyTypeName is null - ? $"{property.Name} = {sourceClassParameterName}.{property.SourcePropertyName};" - : $"{property.Name} = new {property.Type}({sourceClassParameterName}.{property.SourcePropertyName});"); + ? $"{property.Name} = {sourceClassParameterName}.{property.SourcePropertyName};" + : $"{property.Name} = {sourceClassParameterName}.{property.SourcePropertyName}.To{property.Type}();"); } else { diff --git a/test/MapTo.Tests/MapToTests.cs b/test/MapTo.Tests/MapToTests.cs index 92a835e..e75385c 100644 --- a/test/MapTo.Tests/MapToTests.cs +++ b/test/MapTo.Tests/MapToTests.cs @@ -363,7 +363,7 @@ namespace Test Prop1 = baz.Prop1; Prop2 = baz.Prop2; Prop3 = baz.Prop3; - InnerProp1 = new B(baz.InnerProp1); + InnerProp1 = baz.InnerProp1.ToB(); } ".Trim();