diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone.txt b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone.txt index cd7fff6..e1a9825 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone.txt +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone.txt @@ -26,6 +26,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData public AddressDTO MainAddress { get; set; } public ReadOnlyCollection Addresses { get; set; } public int UnitId { get; set; } + public int? Rate { get; set; } } public class UserSourceDTO diff --git a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone_FIXED.txt b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone_FIXED.txt index f639a42..9a4d039 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone_FIXED.txt +++ b/MappingGenerator/MappingGenerator/MappingGenerator.Test/ImplementCloneMethod/TestCaseData/001_DeepClone_FIXED.txt @@ -26,6 +26,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData public AddressDTO MainAddress { get; set; } public ReadOnlyCollection Addresses { get; set; } public int UnitId { get; set; } + public int? Rate { get; set; } public UserDTO Clone() { @@ -59,6 +60,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData BuildingNo = thisAddress.BuildingNo }).ToList().AsReadOnly(), UnitId = UnitId, + Rate = Rate, Id = Id }; } diff --git a/MappingGenerator/MappingGenerator/MappingGenerator/CloneMappingEngine.cs b/MappingGenerator/MappingGenerator/MappingGenerator/CloneMappingEngine.cs index 6dedcc3..d6cb286 100644 --- a/MappingGenerator/MappingGenerator/MappingGenerator/CloneMappingEngine.cs +++ b/MappingGenerator/MappingGenerator/MappingGenerator/CloneMappingEngine.cs @@ -16,6 +16,11 @@ public CloneMappingEngine(SemanticModel semanticModel, SyntaxGenerator syntaxGen protected override bool ShouldCreateConversionBetweenTypes(ITypeSymbol targetType, ITypeSymbol sourceType) { + if (targetType.Equals(sourceType) && SymbolHelper.IsNullable(targetType, out _)) + { + return false; + } + return ObjectHelper.IsSimpleType(targetType) == false && ObjectHelper.IsSimpleType(sourceType) == false; }