From 518009c78ad54afea7035761030c7e1553fb233e Mon Sep 17 00:00:00 2001 From: latonz Date: Sun, 21 Jul 2024 19:03:00 -0500 Subject: [PATCH] fix: only initialize unflattened nullable target members when needed --- docs/docs/breaking-changes/4-0.md | 1 + .../MembersContainerBuilderContext.cs | 48 ++++---- .../MemberMappings/IAssignmentMappings.cs | 8 ++ .../IMemberAssignmentMapping.cs | 6 +- .../IMemberAssignmentMappingContainer.cs | 6 +- .../MemberAssignmentMappingContainer.cs | 27 +++-- .../SourceValue/MappedMemberSourceValue.cs | 11 +- ...erTest.SnapshotGeneratedSource.verified.cs | 2 +- ...erTest.SnapshotGeneratedSource.verified.cs | 34 +++--- ...SnapshotGeneratedSource_NET6_0.verified.cs | 32 +++--- ...erTest.SnapshotGeneratedSource.verified.cs | 88 +++++++------- ...SnapshotGeneratedSource_NET6_0.verified.cs | 86 +++++++------- ...SnapshotGeneratedSource_NET8_0.verified.cs | 86 +++++++------- ...erTest.SnapshotGeneratedSource.verified.cs | 22 ++-- ...SnapshotGeneratedSource_NET6_0.verified.cs | 22 ++-- ...erTest.SnapshotGeneratedSource.verified.cs | 108 +++++++++--------- ...SnapshotGeneratedSource_NET6_0.verified.cs | 108 +++++++++--------- .../Mapping/ObjectPropertyFlatteningTest.cs | 93 ++++++++++++++- ...NullableIntProperties#Mapper.g.verified.cs | 2 +- ...ableUserMappingMethod#Mapper.g.verified.cs | 2 +- ...lNullableIntParameter#Mapper.g.verified.cs | 2 +- 21 files changed, 449 insertions(+), 345 deletions(-) create mode 100644 src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IAssignmentMappings.cs diff --git a/docs/docs/breaking-changes/4-0.md b/docs/docs/breaking-changes/4-0.md index 2329ae9b3a..ca150c4a6e 100644 --- a/docs/docs/breaking-changes/4-0.md +++ b/docs/docs/breaking-changes/4-0.md @@ -16,6 +16,7 @@ description: How to upgrade to Mapperly v4.0 and a list of all its breaking chan - If the `ExplicitCast` conversion is disabled, disable the new `EnumUnderlyingType` conversion too. - Members of foreach mappings are now mapped, which may result in additional members being mapped or new diagnostics being reported. - To account for changed diagnostics adjust your `.editorconfig` as needed, see [updated diagnostics](#updated-diagnostics). +- The ordering of the member assignments in mappings may change, if you rely on the order of members being mapped, you may need to diff and verify the generated source code. ## MapPropertyAttribute constructors diff --git a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs index a16135ce32..498b462e7c 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersContainerBuilderContext.cs @@ -15,6 +15,7 @@ public class MembersContainerBuilderContext(MappingBuilderContext builderCont where T : IMemberAssignmentTypeMapping { private readonly Dictionary _nullDelegateMappings = new(); + private readonly HashSet _initializedNullableTargetPaths = new(); public void AddMemberAssignmentMapping(IMemberAssignmentMapping memberMapping) => AddMemberAssignmentMapping(Mapping, memberMapping); @@ -59,18 +60,28 @@ private void AddMemberAssignmentMapping(IMemberAssignmentMappingContainer contai AddNullMemberInitializers(container, mapping.MemberInfo.TargetMember); container.AddMemberMapping(mapping); MappingAdded(mapping.MemberInfo); + + // if the source value is a non-nullable value, + // the target should be non-null after this assignment and can be set as initialized. + if (mapping.MemberInfo.SourceMember?.MemberPath.IsAnyNullable() != true) + { + _initializedNullableTargetPaths.Add(mapping.MemberInfo.TargetMember); + } } private void AddNullMemberInitializers(IMemberAssignmentMappingContainer container, MemberPath path) { - foreach (var nullableTrailPath in path.ObjectPathNullableSubPaths()) + foreach (var nullablePathList in path.ObjectPathNullableSubPaths()) { - var nullablePath = new NonEmptyMemberPath(path.RootType, nullableTrailPath); + var nullablePath = new NonEmptyMemberPath(path.RootType, nullablePathList); var type = nullablePath.Member.Type.NonNullable(); if (!nullablePath.Member.CanSet) continue; + if (!_initializedNullableTargetPaths.Add(nullablePath)) + continue; + if (!BuilderContext.InstanceConstructors.TryBuild(BuilderContext.Source, type, out var ctor)) { BuilderContext.ReportDiagnostic(DiagnosticDescriptors.NoParameterlessConstructorFound, type); @@ -97,31 +108,28 @@ private MemberNullDelegateAssignmentMapping GetOrCreateNullDelegateMappingForPat if (_nullDelegateMappings.TryGetValue(nullConditionSourcePath, out var mapping)) return mapping; - IMemberAssignmentMappingContainer parentMapping = Mapping; + var parentMapping = FindParentNonNullContainer(nullConditionSourcePath, out var needsNullSafeAccess); + var nullConditionSourcePathGetter = nullConditionSourcePath.BuildGetter(BuilderContext); + mapping = new MemberNullDelegateAssignmentMapping(nullConditionSourcePathGetter, parentMapping, needsNullSafeAccess); + _nullDelegateMappings[nullConditionSourcePath] = mapping; + parentMapping.AddMemberMappingContainer(mapping); + return mapping; + } + private IMemberAssignmentMappingContainer FindParentNonNullContainer(MemberPath nullConditionSourcePath, out bool needsNullSafeAccess) + { // try to reuse parent path mappings and wrap inside them // if the parentMapping is the first nullable path, no need to access the path in the condition in a null-safe way. - var needsNullSafeAccess = false; - foreach (var nullablePath in nullConditionSourcePath.ObjectPathNullableSubPaths().Reverse()) + needsNullSafeAccess = false; + foreach (var nullablePathList in nullConditionSourcePath.ObjectPathNullableSubPaths().Reverse()) { - if ( - _nullDelegateMappings.TryGetValue( - new NonEmptyMemberPath(nullConditionSourcePath.RootType, nullablePath), - out var parentMappingHolder - ) - ) - { - parentMapping = parentMappingHolder; - break; - } + var nullablePath = new NonEmptyMemberPath(nullConditionSourcePath.RootType, nullablePathList); + if (_nullDelegateMappings.TryGetValue(nullablePath, out var parentMappingContainer)) + return parentMappingContainer; needsNullSafeAccess = true; } - var nullConditionSourcePathGetter = nullConditionSourcePath.BuildGetter(BuilderContext); - mapping = new MemberNullDelegateAssignmentMapping(nullConditionSourcePathGetter, parentMapping, needsNullSafeAccess); - _nullDelegateMappings[nullConditionSourcePath] = mapping; - parentMapping.AddMemberMappingContainer(mapping); - return mapping; + return Mapping; } } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IAssignmentMappings.cs b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IAssignmentMappings.cs new file mode 100644 index 0000000000..0aa3bf05f2 --- /dev/null +++ b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IAssignmentMappings.cs @@ -0,0 +1,8 @@ +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Riok.Mapperly.Descriptors.Mappings.MemberMappings; + +public interface IAssignmentMappings +{ + IEnumerable Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess); +} diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMapping.cs index 14ed9a7b68..f71ea5ff46 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMapping.cs @@ -1,13 +1,9 @@ -using Microsoft.CodeAnalysis.CSharp.Syntax; - namespace Riok.Mapperly.Descriptors.Mappings.MemberMappings; /// /// Represents a member assignment mapping or a container of member assignment mappings. /// -public interface IMemberAssignmentMapping +public interface IMemberAssignmentMapping : IAssignmentMappings { MemberMappingInfo MemberInfo { get; } - - IEnumerable Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess); } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMappingContainer.cs b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMappingContainer.cs index ce4274699a..dd930e4c65 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMappingContainer.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/IMemberAssignmentMappingContainer.cs @@ -1,11 +1,9 @@ -using Microsoft.CodeAnalysis.CSharp.Syntax; - namespace Riok.Mapperly.Descriptors.Mappings.MemberMappings; /// /// Represents a container of several . /// -public interface IMemberAssignmentMappingContainer +public interface IMemberAssignmentMappingContainer : IAssignmentMappings { bool HasMemberMapping(IMemberAssignmentMapping mapping); @@ -14,6 +12,4 @@ public interface IMemberAssignmentMappingContainer bool HasMemberMappingContainer(IMemberAssignmentMappingContainer container); void AddMemberMappingContainer(IMemberAssignmentMappingContainer container); - - IEnumerable Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess); } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs index 4189c8e141..923e9f6e46 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/MemberAssignmentMappingContainer.cs @@ -9,20 +9,18 @@ public abstract class MemberAssignmentMappingContainer(IMemberAssignmentMappingC { private readonly HashSet _delegateMappings = new(); private readonly HashSet _childContainers = new(); + private readonly List _mappings = new(); - public virtual IEnumerable Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) - { - var childContainerStatements = _childContainers.SelectMany(x => x.Build(ctx, targetAccess)); - var mappings = _delegateMappings.SelectMany(m => m.Build(ctx, targetAccess)); - return childContainerStatements.Concat(mappings); - } + public virtual IEnumerable Build(TypeMappingBuildContext ctx, ExpressionSyntax targetAccess) => + _mappings.SelectMany(x => x.Build(ctx, targetAccess)); public void AddMemberMappingContainer(IMemberAssignmentMappingContainer container) { - if (!HasMemberMappingContainer(container)) - { - _childContainers.Add(container); - } + if (HasMemberMappingContainer(container)) + return; + + _childContainers.Add(container); + _mappings.Add(container); } public bool HasMemberMappingContainer(IMemberAssignmentMappingContainer container) => @@ -30,10 +28,11 @@ public bool HasMemberMappingContainer(IMemberAssignmentMappingContainer containe public void AddMemberMapping(IMemberAssignmentMapping mapping) { - if (!HasMemberMapping(mapping)) - { - _delegateMappings.Add(mapping); - } + if (HasMemberMapping(mapping)) + return; + + _delegateMappings.Add(mapping); + _mappings.Add(mapping); } public bool HasMemberMapping(IMemberAssignmentMapping mapping) => diff --git a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/SourceValue/MappedMemberSourceValue.cs b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/SourceValue/MappedMemberSourceValue.cs index 5d89387251..dacde868fe 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/SourceValue/MappedMemberSourceValue.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/SourceValue/MappedMemberSourceValue.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Syntax; using Riok.Mapperly.Symbols.Members; @@ -7,6 +8,7 @@ namespace Riok.Mapperly.Descriptors.Mappings.MemberMappings.SourceValue; /// A mapped source member without any null handling. /// (e.g. MapToD(source.A.B) or MapToD(source?.A?.B)). /// +[DebuggerDisplay("MappedMemberSourceValue({_sourceMember}: {_delegateMapping})")] public class MappedMemberSourceValue( INewInstanceMapping delegateMapping, MemberPathGetter sourceMember, @@ -14,17 +16,20 @@ public class MappedMemberSourceValue( bool addValuePropertyOnNullable ) : ISourceValue { - public bool RequiresSourceNullCheck => !nullConditionalAccess && sourceMember.MemberPath.IsAnyNullable(); + private readonly MemberPathGetter _sourceMember = sourceMember; + private readonly INewInstanceMapping _delegateMapping = delegateMapping; + + public bool RequiresSourceNullCheck => !nullConditionalAccess && _sourceMember.MemberPath.IsAnyNullable(); public ExpressionSyntax Build(TypeMappingBuildContext ctx) { ctx = ctx.WithSource( - sourceMember.BuildAccess( + _sourceMember.BuildAccess( ctx.Source, addValuePropertyOnNullable: addValuePropertyOnNullable, nullConditional: nullConditionalAccess ) ); - return delegateMapping.Build(ctx); + return _delegateMapping.Build(ctx); } } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/CircularReferenceMapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/CircularReferenceMapperTest.SnapshotGeneratedSource.verified.cs index 4711348a13..b2d2dbea1f 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/CircularReferenceMapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/CircularReferenceMapperTest.SnapshotGeneratedSource.verified.cs @@ -17,6 +17,7 @@ public static partial class CircularReferenceMapper return existingTargetReference; var target = new global::Riok.Mapperly.IntegrationTests.Dto.CircularReferenceDto(); refHandler.SetReference(source, target); + target.Value = source.Value; if (source.Parent != null) { target.Parent = MapToCircularReferenceDto(source.Parent, refHandler); @@ -25,7 +26,6 @@ public static partial class CircularReferenceMapper { target.Parent = null; } - target.Value = source.Value; return target; } } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource.verified.cs index e0038b3f22..1728cbe05d 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource.verified.cs @@ -1,4 +1,4 @@ -// +// #nullable enable namespace Riok.Mapperly.IntegrationTests.Mapper { @@ -20,6 +20,10 @@ public static partial class DeepCloningMapper IntInitOnlyValue = src.IntInitOnlyValue, RequiredValue = src.RequiredValue, }; + target.IntValue = src.IntValue; + target.StringValue = src.StringValue; + target.RenamedStringValue = src.RenamedStringValue; + target.Flattening = Copy(src.Flattening); if (src.NullableFlattening != null) { target.NullableFlattening = Copy(src.NullableFlattening); @@ -28,6 +32,8 @@ public static partial class DeepCloningMapper { target.NullableFlattening = null; } + target.UnflatteningIdValue = src.UnflatteningIdValue; + target.NullableUnflatteningIdValue = src.NullableUnflatteningIdValue; if (src.NestedNullable != null) { target.NestedNullable = MapToTestObjectNested(src.NestedNullable); @@ -52,6 +58,7 @@ public static partial class DeepCloningMapper { target.NestedMember = null; } + target.StringNullableTargetNotNullable = src.StringNullableTargetNotNullable; if (src.TupleValue != null) { target.TupleValue = MapToValueTupleOfStringAndString(src.TupleValue.Value); @@ -84,21 +91,6 @@ public static partial class DeepCloningMapper { target.NullableReadOnlyObjectCollection = null; } - if (src.SubObject != null) - { - target.SubObject = MapToInheritanceSubObject(src.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = src.IntValue; - target.StringValue = src.StringValue; - target.RenamedStringValue = src.RenamedStringValue; - target.Flattening = Copy(src.Flattening); - target.UnflatteningIdValue = src.UnflatteningIdValue; - target.NullableUnflatteningIdValue = src.NullableUnflatteningIdValue; - target.StringNullableTargetNotNullable = src.StringNullableTargetNotNullable; target.MemoryValue = src.MemoryValue.Span.ToArray(); target.StackValue = new global::System.Collections.Generic.Stack(src.StackValue); target.QueueValue = new global::System.Collections.Generic.Queue(src.QueueValue); @@ -134,6 +126,14 @@ public static partial class DeepCloningMapper target.EnumRawValue = src.EnumRawValue; target.EnumStringValue = src.EnumStringValue; target.EnumReverseStringValue = src.EnumReverseStringValue; + if (src.SubObject != null) + { + target.SubObject = MapToInheritanceSubObject(src.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValue = src.DateTimeValue; target.DateTimeValueTargetDateOnly = src.DateTimeValueTargetDateOnly; target.DateTimeValueTargetTimeOnly = src.DateTimeValueTargetTimeOnly; @@ -154,6 +154,7 @@ public static partial class DeepCloningMapper private static global::Riok.Mapperly.IntegrationTests.Models.TestObjectNestedMember MapToTestObjectNestedMember(global::Riok.Mapperly.IntegrationTests.Models.TestObjectNestedMember source) { var target = new global::Riok.Mapperly.IntegrationTests.Models.TestObjectNestedMember(); + target.NestedMemberId = source.NestedMemberId; if (source.NestedMemberObject != null) { target.NestedMemberObject = MapToTestObjectNested(source.NestedMemberObject); @@ -162,7 +163,6 @@ public static partial class DeepCloningMapper { target.NestedMemberObject = null; } - target.NestedMemberId = source.NestedMemberId; return target; } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs index bc93adef1a..cc5b204be7 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/DeepCloningMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs @@ -20,6 +20,10 @@ public static partial class DeepCloningMapper IntInitOnlyValue = src.IntInitOnlyValue, RequiredValue = src.RequiredValue, }; + target.IntValue = src.IntValue; + target.StringValue = src.StringValue; + target.RenamedStringValue = src.RenamedStringValue; + target.Flattening = Copy(src.Flattening); if (src.NullableFlattening != null) { target.NullableFlattening = Copy(src.NullableFlattening); @@ -28,6 +32,8 @@ public static partial class DeepCloningMapper { target.NullableFlattening = null; } + target.UnflatteningIdValue = src.UnflatteningIdValue; + target.NullableUnflatteningIdValue = src.NullableUnflatteningIdValue; if (src.NestedNullable != null) { target.NestedNullable = MapToTestObjectNested(src.NestedNullable); @@ -52,6 +58,7 @@ public static partial class DeepCloningMapper { target.NestedMember = null; } + target.StringNullableTargetNotNullable = src.StringNullableTargetNotNullable; if (src.TupleValue != null) { target.TupleValue = MapToValueTupleOfStringAndString(src.TupleValue.Value); @@ -84,21 +91,6 @@ public static partial class DeepCloningMapper { target.NullableReadOnlyObjectCollection = null; } - if (src.SubObject != null) - { - target.SubObject = MapToInheritanceSubObject(src.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = src.IntValue; - target.StringValue = src.StringValue; - target.RenamedStringValue = src.RenamedStringValue; - target.Flattening = Copy(src.Flattening); - target.UnflatteningIdValue = src.UnflatteningIdValue; - target.NullableUnflatteningIdValue = src.NullableUnflatteningIdValue; - target.StringNullableTargetNotNullable = src.StringNullableTargetNotNullable; target.MemoryValue = src.MemoryValue.Span.ToArray(); target.StackValue = new global::System.Collections.Generic.Stack(src.StackValue); target.QueueValue = new global::System.Collections.Generic.Queue(src.QueueValue); @@ -137,6 +129,14 @@ public static partial class DeepCloningMapper target.EnumRawValue = src.EnumRawValue; target.EnumStringValue = src.EnumStringValue; target.EnumReverseStringValue = src.EnumReverseStringValue; + if (src.SubObject != null) + { + target.SubObject = MapToInheritanceSubObject(src.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValue = src.DateTimeValue; target.DateTimeValueTargetDateOnly = src.DateTimeValueTargetDateOnly; target.DateTimeValueTargetTimeOnly = src.DateTimeValueTargetTimeOnly; @@ -157,6 +157,7 @@ public static partial class DeepCloningMapper private static global::Riok.Mapperly.IntegrationTests.Models.TestObjectNestedMember MapToTestObjectNestedMember(global::Riok.Mapperly.IntegrationTests.Models.TestObjectNestedMember source) { var target = new global::Riok.Mapperly.IntegrationTests.Models.TestObjectNestedMember(); + target.NestedMemberId = source.NestedMemberId; if (source.NestedMemberObject != null) { target.NestedMemberObject = MapToTestObjectNested(source.NestedMemberObject); @@ -165,7 +166,6 @@ public static partial class DeepCloningMapper { target.NestedMemberObject = null; } - target.NestedMemberId = source.NestedMemberId; return target; } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource.verified.cs index c1608efdf0..bb819ea827 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource.verified.cs @@ -1,4 +1,4 @@ -// +// #nullable enable namespace Riok.Mapperly.IntegrationTests.Mapper { @@ -60,6 +60,10 @@ public partial int ParseableInt(string value) IntInitOnlyValue = DirectInt(testObject.IntInitOnlyValue), RequiredValue = DirectInt(testObject.RequiredValue), }; + target.IntValue = DirectInt(testObject.IntValue); + target.StringValue = testObject.StringValue; + target.RenamedStringValue2 = testObject.RenamedStringValue; + target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); if (testObject.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(testObject.NullableFlattening.IdValue); @@ -68,6 +72,7 @@ public partial int ParseableInt(string value) { target.NullableFlatteningIdValue = null; } + target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); if (testObject.NullableUnflatteningIdValue != null) { target.NullableUnflattening ??= new global::Riok.Mapperly.IntegrationTests.Dto.IdObjectDto(); @@ -88,11 +93,11 @@ public partial int ParseableInt(string value) } if (testObject.NestedMember != null) { + target.NestedMemberId = DirectInt(testObject.NestedMember.NestedMemberId); if (testObject.NestedMember.NestedMemberObject != null) { target.NestedMemberObjectIntValue = DirectInt(testObject.NestedMember.NestedMemberObject.IntValue); } - target.NestedMemberId = DirectInt(testObject.NestedMember.NestedMemberId); } if (testObject.StringNullableTargetNotNullable != null) { @@ -114,6 +119,7 @@ public partial int ParseableInt(string value) { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; if (testObject.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(testObject.NullableReadOnlyObjectCollection); @@ -122,20 +128,6 @@ public partial int ParseableInt(string value) { target.NullableReadOnlyObjectCollection = null; } - if (testObject.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(testObject.IntValue); - target.StringValue = testObject.StringValue; - target.RenamedStringValue2 = testObject.RenamedStringValue; - target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); - target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); - target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array(testObject.SpanValue); target.MemoryValue = MapToInt32Array1(testObject.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(testObject.StackValue, x => ParseableInt(x))); @@ -173,6 +165,14 @@ public partial int ParseableInt(string value) target.EnumRawValue = (byte)testObject.EnumRawValue; target.EnumStringValue = MapToString(testObject.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(testObject.EnumReverseStringValue); + if (testObject.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(testObject.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(testObject.DateTimeValueTargetTimeOnly); target.FormattedIntValue = testObject.IntValue.ToString("C", _formatDeCh); @@ -189,6 +189,9 @@ public partial int ParseableInt(string value) IntInitOnlyValue = DirectInt(dto.IntInitOnlyValue), RequiredValue = DirectInt(dto.RequiredValue), }; + target.IntValue = DirectInt(dto.IntValue); + target.StringValue = dto.StringValue; + target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); if (dto.NullableUnflattening != null) { target.NullableUnflatteningIdValue = CastIntNullable(dto.NullableUnflattening.IdValue); @@ -205,6 +208,8 @@ public partial int ParseableInt(string value) { target.NestedNullable = null; } + target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); + target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; if (dto.TupleValue != null) { target.TupleValue = MapToValueTupleOfStringAndString(dto.TupleValue.Value); @@ -221,6 +226,7 @@ public partial int ParseableInt(string value) { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; if (dto.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedArray(dto.NullableReadOnlyObjectCollection); @@ -229,20 +235,6 @@ public partial int ParseableInt(string value) { target.NullableReadOnlyObjectCollection = null; } - if (dto.SubObject != null) - { - target.SubObject = MapToInheritanceSubObject(dto.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(dto.IntValue); - target.StringValue = dto.StringValue; - target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); - target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); - target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; - target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; target.MemoryValue = MapToStringArray(dto.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(dto.StackValue, x => x.ToString(_formatDeCh))); target.QueueValue = new global::System.Collections.Generic.Queue(global::System.Linq.Enumerable.Select(dto.QueueValue, x => x.ToString(_formatDeCh))); @@ -279,12 +271,25 @@ public partial int ParseableInt(string value) target.EnumRawValue = (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)dto.EnumRawValue; target.EnumStringValue = MapToTestEnum(dto.EnumStringValue); target.EnumReverseStringValue = MapToString1(dto.EnumReverseStringValue); + if (dto.SubObject != null) + { + target.SubObject = MapToInheritanceSubObject(dto.SubObject); + } + else + { + target.SubObject = null; + } return target; } [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.TestObject source, global::Riok.Mapperly.IntegrationTests.Dto.TestObjectDto target) { + target.CtorValue = DirectInt(source.CtorValue); + target.CtorValue2 = DirectInt(source.CtorValue2); + target.IntValue = DirectInt(source.IntValue); + target.StringValue = source.StringValue; + target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); if (source.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(source.NullableFlattening.IdValue); @@ -326,6 +331,7 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; if (source.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(source.NullableReadOnlyObjectCollection); @@ -334,20 +340,6 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test { target.NullableReadOnlyObjectCollection = null; } - if (source.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); - } - else - { - target.SubObject = null; - } - target.CtorValue = DirectInt(source.CtorValue); - target.CtorValue2 = DirectInt(source.CtorValue2); - target.IntValue = DirectInt(source.IntValue); - target.StringValue = source.StringValue; - target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); - target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array(source.SpanValue); target.MemoryValue = MapToInt32Array1(source.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(source.StackValue, x => ParseableInt(x))); @@ -385,6 +377,14 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test target.EnumRawValue = (byte)source.EnumRawValue; target.EnumStringValue = MapToString(source.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(source.EnumReverseStringValue); + if (source.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(source.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(source.DateTimeValueTargetTimeOnly); } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET6_0.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET6_0.verified.cs index d7847e7830..7fc762f333 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET6_0.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET6_0.verified.cs @@ -60,6 +60,10 @@ public partial int ParseableInt(string value) IntInitOnlyValue = DirectInt(testObject.IntInitOnlyValue), RequiredValue = DirectInt(testObject.RequiredValue), }; + target.IntValue = DirectInt(testObject.IntValue); + target.StringValue = testObject.StringValue; + target.RenamedStringValue2 = testObject.RenamedStringValue; + target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); if (testObject.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(testObject.NullableFlattening.IdValue); @@ -68,6 +72,7 @@ public partial int ParseableInt(string value) { target.NullableFlatteningIdValue = null; } + target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); if (testObject.NullableUnflatteningIdValue != null) { target.NullableUnflattening ??= new global::Riok.Mapperly.IntegrationTests.Dto.IdObjectDto(); @@ -88,11 +93,11 @@ public partial int ParseableInt(string value) } if (testObject.NestedMember != null) { + target.NestedMemberId = DirectInt(testObject.NestedMember.NestedMemberId); if (testObject.NestedMember.NestedMemberObject != null) { target.NestedMemberObjectIntValue = DirectInt(testObject.NestedMember.NestedMemberObject.IntValue); } - target.NestedMemberId = DirectInt(testObject.NestedMember.NestedMemberId); } if (testObject.StringNullableTargetNotNullable != null) { @@ -114,6 +119,7 @@ public partial int ParseableInt(string value) { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; if (testObject.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(testObject.NullableReadOnlyObjectCollection); @@ -122,20 +128,6 @@ public partial int ParseableInt(string value) { target.NullableReadOnlyObjectCollection = null; } - if (testObject.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(testObject.IntValue); - target.StringValue = testObject.StringValue; - target.RenamedStringValue2 = testObject.RenamedStringValue; - target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); - target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); - target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array(testObject.SpanValue); target.MemoryValue = MapToInt32Array1(testObject.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(testObject.StackValue, x => ParseableInt(x))); @@ -176,6 +168,14 @@ public partial int ParseableInt(string value) target.EnumRawValue = (byte)testObject.EnumRawValue; target.EnumStringValue = MapToString(testObject.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(testObject.EnumReverseStringValue); + if (testObject.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(testObject.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(testObject.DateTimeValueTargetTimeOnly); target.FormattedIntValue = testObject.IntValue.ToString("C", _formatDeCh); @@ -192,6 +192,9 @@ public partial int ParseableInt(string value) IntInitOnlyValue = DirectInt(dto.IntInitOnlyValue), RequiredValue = DirectInt(dto.RequiredValue), }; + target.IntValue = DirectInt(dto.IntValue); + target.StringValue = dto.StringValue; + target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); if (dto.NullableUnflattening != null) { target.NullableUnflatteningIdValue = CastIntNullable(dto.NullableUnflattening.IdValue); @@ -208,6 +211,8 @@ public partial int ParseableInt(string value) { target.NestedNullable = null; } + target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); + target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; if (dto.TupleValue != null) { target.TupleValue = MapToValueTupleOfStringAndString(dto.TupleValue.Value); @@ -224,6 +229,7 @@ public partial int ParseableInt(string value) { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; if (dto.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedArray(dto.NullableReadOnlyObjectCollection); @@ -232,20 +238,6 @@ public partial int ParseableInt(string value) { target.NullableReadOnlyObjectCollection = null; } - if (dto.SubObject != null) - { - target.SubObject = MapToInheritanceSubObject(dto.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(dto.IntValue); - target.StringValue = dto.StringValue; - target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); - target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); - target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; - target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; target.MemoryValue = MapToStringArray(dto.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(dto.StackValue, x => x.ToString(_formatDeCh))); target.QueueValue = new global::System.Collections.Generic.Queue(global::System.Linq.Enumerable.Select(dto.QueueValue, x => x.ToString(_formatDeCh))); @@ -285,12 +277,25 @@ public partial int ParseableInt(string value) target.EnumRawValue = (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)dto.EnumRawValue; target.EnumStringValue = MapToTestEnum(dto.EnumStringValue); target.EnumReverseStringValue = MapToString1(dto.EnumReverseStringValue); + if (dto.SubObject != null) + { + target.SubObject = MapToInheritanceSubObject(dto.SubObject); + } + else + { + target.SubObject = null; + } return target; } [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.TestObject source, global::Riok.Mapperly.IntegrationTests.Dto.TestObjectDto target) { + target.CtorValue = DirectInt(source.CtorValue); + target.CtorValue2 = DirectInt(source.CtorValue2); + target.IntValue = DirectInt(source.IntValue); + target.StringValue = source.StringValue; + target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); if (source.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(source.NullableFlattening.IdValue); @@ -332,6 +337,7 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; if (source.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(source.NullableReadOnlyObjectCollection); @@ -340,20 +346,6 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test { target.NullableReadOnlyObjectCollection = null; } - if (source.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); - } - else - { - target.SubObject = null; - } - target.CtorValue = DirectInt(source.CtorValue); - target.CtorValue2 = DirectInt(source.CtorValue2); - target.IntValue = DirectInt(source.IntValue); - target.StringValue = source.StringValue; - target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); - target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array(source.SpanValue); target.MemoryValue = MapToInt32Array1(source.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(source.StackValue, x => ParseableInt(x))); @@ -394,6 +386,14 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test target.EnumRawValue = (byte)source.EnumRawValue; target.EnumStringValue = MapToString(source.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(source.EnumReverseStringValue); + if (source.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(source.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(source.DateTimeValueTargetTimeOnly); } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET8_0.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET8_0.verified.cs index bf84bdd8b1..f53dc1e283 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET8_0.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET8_0.verified.cs @@ -60,6 +60,10 @@ public partial int ParseableInt(string value) IntInitOnlyValue = DirectInt(testObject.IntInitOnlyValue), RequiredValue = DirectInt(testObject.RequiredValue), }; + target.IntValue = DirectInt(testObject.IntValue); + target.StringValue = testObject.StringValue; + target.RenamedStringValue2 = testObject.RenamedStringValue; + target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); if (testObject.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(testObject.NullableFlattening.IdValue); @@ -68,6 +72,7 @@ public partial int ParseableInt(string value) { target.NullableFlatteningIdValue = null; } + target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); if (testObject.NullableUnflatteningIdValue != null) { target.NullableUnflattening ??= new global::Riok.Mapperly.IntegrationTests.Dto.IdObjectDto(); @@ -88,11 +93,11 @@ public partial int ParseableInt(string value) } if (testObject.NestedMember != null) { + target.NestedMemberId = DirectInt(testObject.NestedMember.NestedMemberId); if (testObject.NestedMember.NestedMemberObject != null) { target.NestedMemberObjectIntValue = DirectInt(testObject.NestedMember.NestedMemberObject.IntValue); } - target.NestedMemberId = DirectInt(testObject.NestedMember.NestedMemberId); } if (testObject.StringNullableTargetNotNullable != null) { @@ -114,6 +119,7 @@ public partial int ParseableInt(string value) { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; if (testObject.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(testObject.NullableReadOnlyObjectCollection); @@ -122,20 +128,6 @@ public partial int ParseableInt(string value) { target.NullableReadOnlyObjectCollection = null; } - if (testObject.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(testObject.IntValue); - target.StringValue = testObject.StringValue; - target.RenamedStringValue2 = testObject.RenamedStringValue; - target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); - target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); - target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array(testObject.SpanValue); target.MemoryValue = MapToInt32Array1(testObject.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(testObject.StackValue, x => ParseableInt(x))); @@ -176,6 +168,14 @@ public partial int ParseableInt(string value) target.EnumRawValue = (byte)testObject.EnumRawValue; target.EnumStringValue = MapToString(testObject.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(testObject.EnumReverseStringValue); + if (testObject.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(testObject.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(testObject.DateTimeValueTargetTimeOnly); target.FormattedIntValue = testObject.IntValue.ToString("C", _formatDeCh); @@ -193,6 +193,9 @@ public partial int ParseableInt(string value) IntInitOnlyValue = DirectInt(dto.IntInitOnlyValue), RequiredValue = DirectInt(dto.RequiredValue), }; + target.IntValue = DirectInt(dto.IntValue); + target.StringValue = dto.StringValue; + target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); if (dto.NullableUnflattening != null) { target.NullableUnflatteningIdValue = CastIntNullable(dto.NullableUnflattening.IdValue); @@ -209,6 +212,8 @@ public partial int ParseableInt(string value) { target.NestedNullable = null; } + target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); + target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; if (dto.TupleValue != null) { target.TupleValue = MapToValueTupleOfStringAndString(dto.TupleValue.Value); @@ -225,6 +230,7 @@ public partial int ParseableInt(string value) { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; if (dto.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedArray(dto.NullableReadOnlyObjectCollection); @@ -233,20 +239,6 @@ public partial int ParseableInt(string value) { target.NullableReadOnlyObjectCollection = null; } - if (dto.SubObject != null) - { - target.SubObject = MapToInheritanceSubObject(dto.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(dto.IntValue); - target.StringValue = dto.StringValue; - target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); - target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); - target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; - target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; target.MemoryValue = MapToStringArray(dto.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(dto.StackValue, x => x.ToString(_formatDeCh))); target.QueueValue = new global::System.Collections.Generic.Queue(global::System.Linq.Enumerable.Select(dto.QueueValue, x => x.ToString(_formatDeCh))); @@ -286,6 +278,14 @@ public partial int ParseableInt(string value) target.EnumRawValue = (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)dto.EnumRawValue; target.EnumStringValue = MapToTestEnum(dto.EnumStringValue); target.EnumReverseStringValue = MapToString1(dto.EnumReverseStringValue); + if (dto.SubObject != null) + { + target.SubObject = MapToInheritanceSubObject(dto.SubObject); + } + else + { + target.SubObject = null; + } target.SetPrivateValue1(DirectInt(dto.GetPrivateValue1())); return target; } @@ -293,6 +293,11 @@ public partial int ParseableInt(string value) [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.TestObject source, global::Riok.Mapperly.IntegrationTests.Dto.TestObjectDto target) { + target.CtorValue = DirectInt(source.CtorValue); + target.CtorValue2 = DirectInt(source.CtorValue2); + target.IntValue = DirectInt(source.IntValue); + target.StringValue = source.StringValue; + target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); if (source.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(source.NullableFlattening.IdValue); @@ -334,6 +339,7 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; if (source.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(source.NullableReadOnlyObjectCollection); @@ -342,20 +348,6 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test { target.NullableReadOnlyObjectCollection = null; } - if (source.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); - } - else - { - target.SubObject = null; - } - target.CtorValue = DirectInt(source.CtorValue); - target.CtorValue2 = DirectInt(source.CtorValue2); - target.IntValue = DirectInt(source.IntValue); - target.StringValue = source.StringValue; - target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); - target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array(source.SpanValue); target.MemoryValue = MapToInt32Array1(source.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(source.StackValue, x => ParseableInt(x))); @@ -396,6 +388,14 @@ public partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.Test target.EnumRawValue = (byte)source.EnumRawValue; target.EnumStringValue = MapToString(source.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(source.EnumReverseStringValue); + if (source.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(source.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(source.DateTimeValueTargetTimeOnly); target.SetPrivateValue(DirectInt(source.GetPrivateValue())); diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource.verified.cs index 3505a5e65c..c3792bfb24 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource.verified.cs @@ -82,6 +82,11 @@ public static partial class ProjectionMapper IntInitOnlyValue = testObject.IntInitOnlyValue, RequiredValue = testObject.RequiredValue, }; + target.IntValue = testObject.IntValue; + target.StringValue = testObject.StringValue; + target.RenamedStringValue2 = testObject.RenamedStringValue; + target.FlatteningIdValue = testObject.Flattening.IdValue; + target.NullableFlatteningIdValue = testObject.NullableFlattening?.IdValue; if (testObject.NestedNullable != null) { target.NestedNullableIntValue = testObject.NestedNullable.IntValue; @@ -99,6 +104,7 @@ public static partial class ProjectionMapper { target.StringNullableTargetNotNullable = testObject.StringNullableTargetNotNullable; } + target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; if (testObject.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(testObject.NullableReadOnlyObjectCollection); @@ -107,6 +113,11 @@ public static partial class ProjectionMapper { target.NullableReadOnlyObjectCollection = null; } + target.EnumValue = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByValue)testObject.EnumValue; + target.EnumName = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByName)testObject.EnumName; + target.EnumRawValue = (byte)testObject.EnumRawValue; + target.EnumStringValue = MapToString(testObject.EnumStringValue); + target.EnumReverseStringValue = MapToTestEnumDtoByName(testObject.EnumReverseStringValue); if (testObject.SubObject != null) { target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); @@ -115,17 +126,6 @@ public static partial class ProjectionMapper { target.SubObject = null; } - target.IntValue = testObject.IntValue; - target.StringValue = testObject.StringValue; - target.RenamedStringValue2 = testObject.RenamedStringValue; - target.FlatteningIdValue = testObject.Flattening.IdValue; - target.NullableFlatteningIdValue = testObject.NullableFlattening?.IdValue; - target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; - target.EnumValue = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByValue)testObject.EnumValue; - target.EnumName = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByName)testObject.EnumName; - target.EnumRawValue = (byte)testObject.EnumRawValue; - target.EnumStringValue = MapToString(testObject.EnumStringValue); - target.EnumReverseStringValue = MapToTestEnumDtoByName(testObject.EnumReverseStringValue); target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(testObject.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(testObject.DateTimeValueTargetTimeOnly); target.ManuallyMapped = MapManual(testObject.ManuallyMapped); diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs index 641afe26da..ba7014eef4 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/ProjectionMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs @@ -82,6 +82,11 @@ public static partial class ProjectionMapper IntInitOnlyValue = testObject.IntInitOnlyValue, RequiredValue = testObject.RequiredValue, }; + target.IntValue = testObject.IntValue; + target.StringValue = testObject.StringValue; + target.RenamedStringValue2 = testObject.RenamedStringValue; + target.FlatteningIdValue = testObject.Flattening.IdValue; + target.NullableFlatteningIdValue = testObject.NullableFlattening?.IdValue; if (testObject.NestedNullable != null) { target.NestedNullableIntValue = testObject.NestedNullable.IntValue; @@ -99,6 +104,7 @@ public static partial class ProjectionMapper { target.StringNullableTargetNotNullable = testObject.StringNullableTargetNotNullable; } + target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; if (testObject.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(testObject.NullableReadOnlyObjectCollection); @@ -107,6 +113,11 @@ public static partial class ProjectionMapper { target.NullableReadOnlyObjectCollection = null; } + target.EnumValue = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByValue)testObject.EnumValue; + target.EnumName = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByName)testObject.EnumName; + target.EnumRawValue = (byte)testObject.EnumRawValue; + target.EnumStringValue = MapToString(testObject.EnumStringValue); + target.EnumReverseStringValue = MapToTestEnumDtoByName(testObject.EnumReverseStringValue); if (testObject.SubObject != null) { target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); @@ -115,17 +126,6 @@ public static partial class ProjectionMapper { target.SubObject = null; } - target.IntValue = testObject.IntValue; - target.StringValue = testObject.StringValue; - target.RenamedStringValue2 = testObject.RenamedStringValue; - target.FlatteningIdValue = testObject.Flattening.IdValue; - target.NullableFlatteningIdValue = testObject.NullableFlattening?.IdValue; - target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; - target.EnumValue = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByValue)testObject.EnumValue; - target.EnumName = (global::Riok.Mapperly.IntegrationTests.Dto.TestEnumDtoByName)testObject.EnumName; - target.EnumRawValue = (byte)testObject.EnumRawValue; - target.EnumStringValue = MapToString(testObject.EnumStringValue); - target.EnumReverseStringValue = MapToTestEnumDtoByName(testObject.EnumReverseStringValue); target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(testObject.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(testObject.DateTimeValueTargetTimeOnly); target.ManuallyMapped = MapManual(testObject.ManuallyMapped); diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource.verified.cs index e38a170295..f288efc9f9 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource.verified.cs @@ -91,6 +91,9 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes IntInitOnlyValue = DirectInt(src.IntInitOnlyValue), RequiredValue = DirectInt(src.RequiredValue), }; + target.IntValue = DirectInt(src.IntValue); + target.StringValue = src.StringValue; + target.FlatteningIdValue = DirectInt(src.Flattening.IdValue); if (src.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(src.NullableFlattening.IdValue); @@ -132,6 +135,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = src.SourceTargetSameObjectType; if (src.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(src.NullableReadOnlyObjectCollection); @@ -140,18 +144,6 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableReadOnlyObjectCollection = null; } - if (src.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(src.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(src.IntValue); - target.StringValue = src.StringValue; - target.FlatteningIdValue = DirectInt(src.Flattening.IdValue); - target.SourceTargetSameObjectType = src.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array1(src.SpanValue); target.MemoryValue = MapToInt32Array2(src.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(src.StackValue, x => ParseableInt(x))); @@ -186,6 +178,14 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes target.EnumRawValue = (byte)src.EnumRawValue; target.EnumStringValue = MapToString(src.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(src.EnumReverseStringValue); + if (src.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(src.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(src.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(src.DateTimeValueTargetTimeOnly); return target; @@ -199,6 +199,10 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes IntInitOnlyValue = DirectInt(testObject.IntInitOnlyValue), RequiredValue = DirectInt(testObject.RequiredValue), }; + target.IntValue = DirectInt(testObject.IntValue); + target.StringValue = testObject.StringValue; + target.RenamedStringValue2 = testObject.RenamedStringValue; + target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); if (testObject.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(testObject.NullableFlattening.IdValue); @@ -207,6 +211,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableFlatteningIdValue = null; } + target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); if (testObject.NullableUnflatteningIdValue != null) { target.NullableUnflattening ??= new global::Riok.Mapperly.IntegrationTests.Dto.IdObjectDto(); @@ -245,6 +250,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; if (testObject.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(testObject.NullableReadOnlyObjectCollection); @@ -253,20 +259,6 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableReadOnlyObjectCollection = null; } - if (testObject.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(testObject.IntValue); - target.StringValue = testObject.StringValue; - target.RenamedStringValue2 = testObject.RenamedStringValue; - target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); - target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); - target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array1(testObject.SpanValue); target.MemoryValue = MapToInt32Array2(testObject.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(testObject.StackValue, x => ParseableInt(x))); @@ -301,6 +293,14 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes target.EnumRawValue = (byte)testObject.EnumRawValue; target.EnumStringValue = MapToString(testObject.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(testObject.EnumReverseStringValue); + if (testObject.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(testObject.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(testObject.DateTimeValueTargetTimeOnly); return target; @@ -314,6 +314,9 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes IntInitOnlyValue = DirectInt(dto.IntInitOnlyValue), RequiredValue = DirectInt(dto.RequiredValue), }; + target.IntValue = DirectInt(dto.IntValue); + target.StringValue = dto.StringValue; + target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); if (dto.NullableUnflattening != null) { target.NullableUnflatteningIdValue = CastIntNullable(dto.NullableUnflattening.IdValue); @@ -330,6 +333,8 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NestedNullable = null; } + target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); + target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; if (dto.TupleValue != null) { target.TupleValue = MapToValueTupleOfStringAndString(dto.TupleValue.Value); @@ -346,6 +351,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; if (dto.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedArray(dto.NullableReadOnlyObjectCollection); @@ -354,20 +360,6 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableReadOnlyObjectCollection = null; } - if (dto.SubObject != null) - { - target.SubObject = MapToInheritanceSubObject(dto.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(dto.IntValue); - target.StringValue = dto.StringValue; - target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); - target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); - target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; - target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; target.MemoryValue = MapToStringArray(dto.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(dto.StackValue, x => x.ToString())); target.QueueValue = new global::System.Collections.Generic.Queue(global::System.Linq.Enumerable.Select(dto.QueueValue, x => x.ToString())); @@ -404,12 +396,25 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes target.EnumRawValue = (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)dto.EnumRawValue; target.EnumStringValue = MapToTestEnum(dto.EnumStringValue); target.EnumReverseStringValue = MapToString1(dto.EnumReverseStringValue); + if (dto.SubObject != null) + { + target.SubObject = MapToInheritanceSubObject(dto.SubObject); + } + else + { + target.SubObject = null; + } return target; } [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.TestObject source, global::Riok.Mapperly.IntegrationTests.Dto.TestObjectDto target) { + target.CtorValue = DirectInt(source.CtorValue); + target.CtorValue2 = DirectInt(source.CtorValue2); + target.IntValue = DirectInt(source.IntValue); + target.StringValue = source.StringValue; + target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); if (source.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(source.NullableFlattening.IdValue); @@ -451,6 +456,7 @@ public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Mode { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; if (source.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(source.NullableReadOnlyObjectCollection); @@ -459,20 +465,6 @@ public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Mode { target.NullableReadOnlyObjectCollection = null; } - if (source.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); - } - else - { - target.SubObject = null; - } - target.CtorValue = DirectInt(source.CtorValue); - target.CtorValue2 = DirectInt(source.CtorValue2); - target.IntValue = DirectInt(source.IntValue); - target.StringValue = source.StringValue; - target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); - target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array1(source.SpanValue); target.MemoryValue = MapToInt32Array2(source.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(source.StackValue, x => ParseableInt(x))); @@ -507,6 +499,14 @@ public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Mode target.EnumRawValue = (byte)source.EnumRawValue; target.EnumStringValue = MapToString(source.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(source.EnumReverseStringValue); + if (source.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(source.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(source.DateTimeValueTargetTimeOnly); } diff --git a/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs b/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs index b5a222def1..93455f63b9 100644 --- a/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs +++ b/test/Riok.Mapperly.IntegrationTests/_snapshots/StaticMapperTest.SnapshotGeneratedSource_NET6_0.verified.cs @@ -91,6 +91,9 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes IntInitOnlyValue = DirectInt(src.IntInitOnlyValue), RequiredValue = DirectInt(src.RequiredValue), }; + target.IntValue = DirectInt(src.IntValue); + target.StringValue = src.StringValue; + target.FlatteningIdValue = DirectInt(src.Flattening.IdValue); if (src.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(src.NullableFlattening.IdValue); @@ -132,6 +135,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = src.SourceTargetSameObjectType; if (src.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(src.NullableReadOnlyObjectCollection); @@ -140,18 +144,6 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableReadOnlyObjectCollection = null; } - if (src.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(src.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(src.IntValue); - target.StringValue = src.StringValue; - target.FlatteningIdValue = DirectInt(src.Flattening.IdValue); - target.SourceTargetSameObjectType = src.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array1(src.SpanValue); target.MemoryValue = MapToInt32Array2(src.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(src.StackValue, x => ParseableInt(x))); @@ -188,6 +180,14 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes target.EnumRawValue = (byte)src.EnumRawValue; target.EnumStringValue = MapToString(src.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(src.EnumReverseStringValue); + if (src.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(src.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(src.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(src.DateTimeValueTargetTimeOnly); return target; @@ -201,6 +201,10 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes IntInitOnlyValue = DirectInt(testObject.IntInitOnlyValue), RequiredValue = DirectInt(testObject.RequiredValue), }; + target.IntValue = DirectInt(testObject.IntValue); + target.StringValue = testObject.StringValue; + target.RenamedStringValue2 = testObject.RenamedStringValue; + target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); if (testObject.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(testObject.NullableFlattening.IdValue); @@ -209,6 +213,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableFlatteningIdValue = null; } + target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); if (testObject.NullableUnflatteningIdValue != null) { target.NullableUnflattening ??= new global::Riok.Mapperly.IntegrationTests.Dto.IdObjectDto(); @@ -247,6 +252,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; if (testObject.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(testObject.NullableReadOnlyObjectCollection); @@ -255,20 +261,6 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableReadOnlyObjectCollection = null; } - if (testObject.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(testObject.IntValue); - target.StringValue = testObject.StringValue; - target.RenamedStringValue2 = testObject.RenamedStringValue; - target.FlatteningIdValue = DirectInt(testObject.Flattening.IdValue); - target.Unflattening.IdValue = DirectInt(testObject.UnflatteningIdValue); - target.SourceTargetSameObjectType = testObject.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array1(testObject.SpanValue); target.MemoryValue = MapToInt32Array2(testObject.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(testObject.StackValue, x => ParseableInt(x))); @@ -305,6 +297,14 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes target.EnumRawValue = (byte)testObject.EnumRawValue; target.EnumStringValue = MapToString(testObject.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(testObject.EnumReverseStringValue); + if (testObject.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(testObject.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(testObject.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(testObject.DateTimeValueTargetTimeOnly); return target; @@ -318,6 +318,9 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes IntInitOnlyValue = DirectInt(dto.IntInitOnlyValue), RequiredValue = DirectInt(dto.RequiredValue), }; + target.IntValue = DirectInt(dto.IntValue); + target.StringValue = dto.StringValue; + target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); if (dto.NullableUnflattening != null) { target.NullableUnflatteningIdValue = CastIntNullable(dto.NullableUnflattening.IdValue); @@ -334,6 +337,8 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NestedNullable = null; } + target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); + target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; if (dto.TupleValue != null) { target.TupleValue = MapToValueTupleOfStringAndString(dto.TupleValue.Value); @@ -350,6 +355,7 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; if (dto.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedArray(dto.NullableReadOnlyObjectCollection); @@ -358,20 +364,6 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes { target.NullableReadOnlyObjectCollection = null; } - if (dto.SubObject != null) - { - target.SubObject = MapToInheritanceSubObject(dto.SubObject); - } - else - { - target.SubObject = null; - } - target.IntValue = DirectInt(dto.IntValue); - target.StringValue = dto.StringValue; - target.UnflatteningIdValue = DirectInt(dto.Unflattening.IdValue); - target.NestedNullableTargetNotNullable = MapToTestObjectNested(dto.NestedNullableTargetNotNullable); - target.StringNullableTargetNotNullable = dto.StringNullableTargetNotNullable; - target.SourceTargetSameObjectType = dto.SourceTargetSameObjectType; target.MemoryValue = MapToStringArray(dto.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(dto.StackValue, x => x.ToString())); target.QueueValue = new global::System.Collections.Generic.Queue(global::System.Linq.Enumerable.Select(dto.QueueValue, x => x.ToString())); @@ -411,12 +403,25 @@ public static partial void MapIdTargetFirst(global::Riok.Mapperly.IntegrationTes target.EnumRawValue = (global::Riok.Mapperly.IntegrationTests.Models.TestEnum)dto.EnumRawValue; target.EnumStringValue = MapToTestEnum(dto.EnumStringValue); target.EnumReverseStringValue = MapToString1(dto.EnumReverseStringValue); + if (dto.SubObject != null) + { + target.SubObject = MapToInheritanceSubObject(dto.SubObject); + } + else + { + target.SubObject = null; + } return target; } [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Models.TestObject source, global::Riok.Mapperly.IntegrationTests.Dto.TestObjectDto target) { + target.CtorValue = DirectInt(source.CtorValue); + target.CtorValue2 = DirectInt(source.CtorValue2); + target.IntValue = DirectInt(source.IntValue); + target.StringValue = source.StringValue; + target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); if (source.NullableFlattening != null) { target.NullableFlatteningIdValue = CastIntNullable(source.NullableFlattening.IdValue); @@ -458,6 +463,7 @@ public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Mode { target.RecursiveObject = null; } + target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; if (source.NullableReadOnlyObjectCollection != null) { target.NullableReadOnlyObjectCollection = MapToTestObjectNestedDtoArray(source.NullableReadOnlyObjectCollection); @@ -466,20 +472,6 @@ public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Mode { target.NullableReadOnlyObjectCollection = null; } - if (source.SubObject != null) - { - target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); - } - else - { - target.SubObject = null; - } - target.CtorValue = DirectInt(source.CtorValue); - target.CtorValue2 = DirectInt(source.CtorValue2); - target.IntValue = DirectInt(source.IntValue); - target.StringValue = source.StringValue; - target.FlatteningIdValue = DirectInt(source.Flattening.IdValue); - target.SourceTargetSameObjectType = source.SourceTargetSameObjectType; target.SpanValue = MapToInt32Array1(source.SpanValue); target.MemoryValue = MapToInt32Array2(source.MemoryValue.Span); target.StackValue = new global::System.Collections.Generic.Stack(global::System.Linq.Enumerable.Select(source.StackValue, x => ParseableInt(x))); @@ -516,6 +508,14 @@ public static partial void UpdateDto(global::Riok.Mapperly.IntegrationTests.Mode target.EnumRawValue = (byte)source.EnumRawValue; target.EnumStringValue = MapToString(source.EnumStringValue); target.EnumReverseStringValue = MapToTestEnumDtoByValue(source.EnumReverseStringValue); + if (source.SubObject != null) + { + target.SubObject = MapToInheritanceSubObjectDto(source.SubObject); + } + else + { + target.SubObject = null; + } target.DateTimeValueTargetDateOnly = global::System.DateOnly.FromDateTime(source.DateTimeValueTargetDateOnly); target.DateTimeValueTargetTimeOnly = global::System.TimeOnly.FromDateTime(source.DateTimeValueTargetTimeOnly); } diff --git a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyFlatteningTest.cs b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyFlatteningTest.cs index bf20f64c19..1a9c8f9d0d 100644 --- a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyFlatteningTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyFlatteningTest.cs @@ -620,16 +620,107 @@ public void ManualNestedPropertyNullablePath() if (source.Value1 != null) { target.Value2 ??= new global::E(); + target.Value2.Id200 = source.Value1.Id100; if (source.Value1.Value1 != null) { target.Value2.Value2 ??= new global::F(); target.Value2.Value2.Id2 = source.Value1.Value1.Id1; target.Value2.Value2.Id20 = source.Value1.Value1.Id10; } - target.Value2.Id200 = source.Value1.Id100; } return target; """ ); } + + [Fact] + public void ManualUnflattenedPropertyNullablePathShouldNotNullInitialize() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty("MyValueId", "Value.Id")] + [MapProperty("MyValueId2", "Value.Id2")] + [MapProperty("Value", "Value")] + public partial B Map(A source); + """, + "class A { public string MyValueId { get; set; } public string MyValueId2 { get; set; } public C Value { get; set; } }", + "class B { public C? Value { get; set; } }", + "class C { public string Id { get; set; } public string Id2 { get; set; } }" + ); + + TestHelper + .GenerateMapper(source) + .Should() + .HaveSingleMethodBody( + """ + var target = new global::B(); + target.Value = source.Value; + target.Value.Id = source.MyValueId; + target.Value.Id2 = source.MyValueId2; + return target; + """ + ); + } + + [Fact] + public void ManualUnflattenedPropertyNullablePathShouldNullInitialize() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty("MyValueId", "Value.Id")] + [MapProperty("MyValueId2", "Value.Id2")] + [MapProperty("Value", "Value")] + public partial B Map(A source); + """, + "class A { public string MyValueId { get; set; } public string MyValueId2 { get; set; } public C? Value { get; set; } }", + "class B { public C? Value { get; set; } }", + "class C { public string Id { get; set; } public string Id2 { get; set; } }" + ); + + TestHelper + .GenerateMapper(source) + .Should() + .HaveSingleMethodBody( + """ + var target = new global::B(); + target.Value = source.Value; + target.Value ??= new global::C(); + target.Value.Id = source.MyValueId; + target.Value.Id2 = source.MyValueId2; + return target; + """ + ); + } + + [Fact] + public void ManualUnflattenedPropertyDeepNullablePathShouldNotNullInitialize() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty("MyValueId", "My.Value.Id")] + [MapProperty("MyValueId2", "My.Value.Id2")] + [MapProperty("My", "My")] + [MapProperty("Value", "My.Value")] + public partial B Map(A source); + """, + "class A { public string MyValueId { get; set; } public string MyValueId2 { get; set; } public C My { get; set; } public D Value { get; set; } }", + "class B { public C? My { get; set; } }", + "class C { public D? Value { get; set; } }", + "class D { public string Id { get; set; } public string Id2 { get; set; } }" + ); + + TestHelper + .GenerateMapper(source) + .Should() + .HaveSingleMethodBody( + """ + var target = new global::B(); + target.My = source.My; + target.My.Value = source.Value; + target.My.Value.Id = source.MyValueId; + target.My.Value.Id2 = source.MyValueId2; + return target; + """ + ); + } } diff --git a/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyNullableTest.NullableIntWithAdditionalFlattenedValueToNonNullableIntProperties#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyNullableTest.NullableIntWithAdditionalFlattenedValueToNonNullableIntProperties#Mapper.g.verified.cs index 51c5e93da9..6d58993fa5 100644 --- a/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyNullableTest.NullableIntWithAdditionalFlattenedValueToNonNullableIntProperties#Mapper.g.verified.cs +++ b/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyNullableTest.NullableIntWithAdditionalFlattenedValueToNonNullableIntProperties#Mapper.g.verified.cs @@ -9,11 +9,11 @@ public partial class Mapper var target = new global::B(); if (source.Nested != null) { + target.Nested = MapToD(source.Nested); if (source.Nested.Value2 != null) { target.NestedValue2 = source.Nested.Value2.Value; } - target.Nested = MapToD(source.Nested); } return target; } diff --git a/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyUseNamedMappingTest.ShouldPassNullValueToNullableUserMappingMethod#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyUseNamedMappingTest.ShouldPassNullValueToNullableUserMappingMethod#Mapper.g.verified.cs index 2b0d125042..308272297b 100644 --- a/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyUseNamedMappingTest.ShouldPassNullValueToNullableUserMappingMethod#Mapper.g.verified.cs +++ b/test/Riok.Mapperly.Tests/_snapshots/ObjectPropertyUseNamedMappingTest.ShouldPassNullValueToNullableUserMappingMethod#Mapper.g.verified.cs @@ -7,11 +7,11 @@ public partial class Mapper public partial global::B Map(global::A source) { var target = new global::B(); + target.Value = MapString(source.Value); if (source.Value2 != null) { target.Value2 = source.Value2; } - target.Value = MapString(source.Value); return target; } } \ No newline at end of file diff --git a/test/Riok.Mapperly.Tests/_snapshots/UserMethodAdditionalParametersTest.AdditionalNullableIntParameter#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/UserMethodAdditionalParametersTest.AdditionalNullableIntParameter#Mapper.g.verified.cs index 4fbe6747f7..a2a9154c1d 100644 --- a/test/Riok.Mapperly.Tests/_snapshots/UserMethodAdditionalParametersTest.AdditionalNullableIntParameter#Mapper.g.verified.cs +++ b/test/Riok.Mapperly.Tests/_snapshots/UserMethodAdditionalParametersTest.AdditionalNullableIntParameter#Mapper.g.verified.cs @@ -7,11 +7,11 @@ public partial class Mapper partial global::B Map(global::A src, int? value) { var target = new global::B(); + target.StringValue = src.StringValue; if (value != null) { target.Value = value.Value.ToString(); } - target.StringValue = src.StringValue; return target; } } \ No newline at end of file