Use extension method to map the nested objects.

This commit is contained in:
Mohammadreza Taikandi 2021-02-07 10:55:08 +00:00
parent 36161b728c
commit 542cdb05f8
2 changed files with 3 additions and 3 deletions

View File

@ -71,8 +71,8 @@ namespace MapTo.Sources
if (property.TypeConverter is null) if (property.TypeConverter is null)
{ {
builder.WriteLine(property.MappedSourcePropertyTypeName is null builder.WriteLine(property.MappedSourcePropertyTypeName is null
? $"{property.Name} = {sourceClassParameterName}.{property.SourcePropertyName};" ? $"{property.Name} = {sourceClassParameterName}.{property.SourcePropertyName};"
: $"{property.Name} = new {property.Type}({sourceClassParameterName}.{property.SourcePropertyName});"); : $"{property.Name} = {sourceClassParameterName}.{property.SourcePropertyName}.To{property.Type}();");
} }
else else
{ {

View File

@ -363,7 +363,7 @@ namespace Test
Prop1 = baz.Prop1; Prop1 = baz.Prop1;
Prop2 = baz.Prop2; Prop2 = baz.Prop2;
Prop3 = baz.Prop3; Prop3 = baz.Prop3;
InnerProp1 = new B(baz.InnerProp1); InnerProp1 = baz.InnerProp1.ToB();
} }
".Trim(); ".Trim();