From a1da7d4e5a2a6f4fb4d6759810de0146577610b2 Mon Sep 17 00:00:00 2001 From: Jan Trejbal Date: Thu, 19 Nov 2026 21:24:38 +0000 Subject: [PATCH] fix: pass [MappingTargetOriginalValue] to mappings referenced by Use A user-implemented mapping referenced with Use received the default value for its [MappingTargetOriginalValue] parameter. The member mapping builder looked for the parameter on the wrapper that UseNamedMappingBuilder creates, not on the referenced mapping. CompositeMapping now holds the referenced mapping and its optional input and output conversions. Only the referenced mapping receives the target value. The target value is passed only when the target member is readable and its type converts implicitly to the parameter type. Otherwise the parameter receives its default value, and Mapperly reports RMG102 for a member that is not readable and RMG101 for a type that does not fit. Co-Authored-By: Claude --- docs/docs/breaking-changes/5-0.md | 1 + .../user-implemented-methods.mdx | 11 + src/Riok.Mapperly/AnalyzerReleases.Shipped.md | 2 + .../MemberMappingBuilder.cs | 53 +++- .../MappingBuilders/UseNamedMappingBuilder.cs | 24 +- .../Descriptors/Mappings/CompositeMapping.cs | 20 +- .../Mappings/TypeMappingBuildContext.cs | 2 +- .../Diagnostics/DiagnosticDescriptors.cs | 18 ++ ...serMethodMappingTargetOriginalValueTest.cs | 256 ++++++++++++++++++ ...nalStaticNamedMapping#Mapper.g.verified.cs | 11 + ...pingForExistingTarget#Mapper.g.verified.cs | 11 + ...MappingForNewInstance#Mapper.g.verified.cs | 13 + ...ithSupertypeParameter#Mapper.g.verified.cs | 11 + ...thAdditionalParameter#Mapper.g.verified.cs | 13 + ...dMappingForProjection#Mapper.g.verified.cs | 20 ++ 15 files changed, 440 insertions(+), 26 deletions(-) create mode 100644 test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.ExternalStaticNamedMapping#Mapper.g.verified.cs create mode 100644 test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForExistingTarget#Mapper.g.verified.cs create mode 100644 test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForNewInstance#Mapper.g.verified.cs create mode 100644 test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingFromSourceWithSupertypeParameter#Mapper.g.verified.cs create mode 100644 test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingWithAdditionalParameter#Mapper.g.verified.cs create mode 100644 test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NonInlinedNamedMappingForProjection#Mapper.g.verified.cs diff --git a/docs/docs/breaking-changes/5-0.md b/docs/docs/breaking-changes/5-0.md index c1c7a6e029..a094eff720 100644 --- a/docs/docs/breaking-changes/5-0.md +++ b/docs/docs/breaking-changes/5-0.md @@ -25,6 +25,7 @@ description: How to upgrade to Mapperly 5.0 and a list of all its breaking chang - `RMG032` (enum mapping strategy not supported in projection mappings) is now an error and no cast fallback is generated, [see below](#rmg032-is-now-an-error). - User-implemented mappings are no longer reused for mappings with inexact source or target types, [see below](#user-implemented-mappings-require-exact-types). - Methods annotated with `[UserMapping(Ignore = true)]` are skipped before their signature is validated, so `RMG001` is no longer reported for ignored methods with unsupported signatures. +- A `[MappingTargetOriginalValue]` parameter receives its default value when the target member is not readable or has a type the parameter cannot take. The new warnings `RMG102` and `RMG101` report these cases, see [target original value parameter](../configuration/user-implemented-methods.mdx#target-original-value-parameter). ## User-implemented mappings require exact types diff --git a/docs/docs/configuration/user-implemented-methods.mdx b/docs/docs/configuration/user-implemented-methods.mdx index 04407ecac4..097067d911 100644 --- a/docs/docs/configuration/user-implemented-methods.mdx +++ b/docs/docs/configuration/user-implemented-methods.mdx @@ -222,3 +222,14 @@ This lets the method use the existing destination value e.g. as a fallback when ``` + +Mapperly passes the current value only when all of the following apply: + +- The target member is set by an assignment. + Init-only members, constructor parameters and queryable projections are not. +- The target member is readable. +- The target member type converts implicitly to the parameter type. + +Otherwise the parameter receives its default value. +For a target member set by an assignment, Mapperly reports `RMG102` if the member is not readable +and `RMG101` if its type does not fit. diff --git a/src/Riok.Mapperly/AnalyzerReleases.Shipped.md b/src/Riok.Mapperly/AnalyzerReleases.Shipped.md index d4fe43f0ee..384013d4d7 100644 --- a/src/Riok.Mapperly/AnalyzerReleases.Shipped.md +++ b/src/Riok.Mapperly/AnalyzerReleases.Shipped.md @@ -226,6 +226,8 @@ RMG097 | Mapper | Error | MapValue Use method parameters cannot be satisfied RMG098 | Mapper | Error | Named mapping additional parameters cannot be satisfied RMG099 | Mapper | Error | Duplicate additional parameter names differing only in casing RMG100 | Mapper | Error | [MappingTargetOriginalValue] is not supported on generated (partial) mapping methods. +RMG101 | Mapper | Warning | The target member type does not match the [MappingTargetOriginalValue] parameter type +RMG102 | Mapper | Warning | The target member cannot be read for the [MappingTargetOriginalValue] parameter ### Changed Rules diff --git a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs index 8423ef64f9..0726a814da 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBodyBuilders/MemberMappingBuilder.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Riok.Mapperly.Descriptors.MappingBodyBuilders.BuilderContext; using Riok.Mapperly.Descriptors.Mappings; using Riok.Mapperly.Descriptors.Mappings.MemberMappings; @@ -104,7 +105,7 @@ public static bool TryBuild( ); } - var targetValueGetter = GetTargetValueGetterIfNeeded(ctx, delegateMapping, memberMappingInfo.TargetMember); + var targetValueGetter = GetTargetValueGetterIfNeeded(ctx, delegateMapping, memberMappingInfo.TargetMember, codeStyle); if ( (memberSourceNullable == delegateSourceNullable && memberTargetAcceptsNull == delegateTargetNullable) @@ -174,11 +175,51 @@ public static bool TryBuild( private static MemberPathGetter? GetTargetValueGetterIfNeeded( IMembersBuilderContext ctx, INewInstanceMapping delegateMapping, - NonEmptyMemberPath targetMember - ) => - delegateMapping is UserImplementedMethodMapping { TargetOriginalValueParameter: not null } - ? targetMember.BuildGetter(ctx.BuilderContext) - : null; + NonEmptyMemberPath targetMember, + CodeStyle codeStyle + ) + { + if (delegateMapping is CompositeMapping composite) + delegateMapping = composite.NamedMapping; + + if (delegateMapping is not UserImplementedMethodMapping { TargetOriginalValueParameter: { } parameter } userMapping) + return null; + + // An initializer never passes the target value, so a diagnostic only helps for an assignment. + var reportDiagnostics = codeStyle == CodeStyle.Statement; + + if (!targetMember.Member.CanGet) + { + if (reportDiagnostics) + { + ctx.BuilderContext.ReportDiagnostic( + DiagnosticDescriptors.MappingTargetOriginalValueMemberNotReadable, + targetMember.ToDisplayString(), + parameter.Name, + userMapping.Method.Name + ); + } + + return null; + } + + // The getter reads the member itself, so its type decides whether the parameter accepts the value. + if (ctx.BuilderContext.Compilation.ClassifyConversion(targetMember.Member.Type, parameter.Type).IsImplicit) + return targetMember.BuildGetter(ctx.BuilderContext); + + if (reportDiagnostics) + { + ctx.BuilderContext.ReportDiagnostic( + DiagnosticDescriptors.MappingTargetOriginalValueTypeMismatch, + targetMember.ToDisplayString(), + parameter.Name, + parameter.Type.ToDisplayString(), + userMapping.Method.Name + ); + } + + return null; + } private static bool ValidateLoopMapping( IMembersBuilderContext ctx, diff --git a/src/Riok.Mapperly/Descriptors/MappingBuilders/UseNamedMappingBuilder.cs b/src/Riok.Mapperly/Descriptors/MappingBuilders/UseNamedMappingBuilder.cs index b9641c5db0..43e705a86f 100644 --- a/src/Riok.Mapperly/Descriptors/MappingBuilders/UseNamedMappingBuilder.cs +++ b/src/Riok.Mapperly/Descriptors/MappingBuilders/UseNamedMappingBuilder.cs @@ -47,20 +47,16 @@ public static class UseNamedMappingBuilder var differentSourceType = !SymbolEqualityComparer.IncludeNullability.Equals(ctx.Source, mapping.SourceType); var differentTargetType = !SymbolEqualityComparer.IncludeNullability.Equals(ctx.Target, mapping.TargetType); - // use a delegate mapping, - // otherwise the user-defined method mapping may get built twice - // (if it is returned here directly, it is re-added to the mappings to be built) - if (!differentSourceType && !differentTargetType) - return new DelegateMapping(mapping.SourceType, mapping.TargetType, mapping); + var inputMapping = differentSourceType ? TryMapSource(ctx, mapping) : null; + if (differentSourceType && inputMapping == null) + return null; - if (differentSourceType) - { - mapping = TryMapSource(ctx, mapping); - if (mapping == null) - return null; - } + var outputMapping = differentTargetType ? TryMapTarget(ctx, mapping) : null; + if (differentTargetType && outputMapping == null) + return null; - return differentTargetType ? TryMapTarget(ctx, mapping) : mapping; + // Wrap even exact matches to avoid re-adding the named mapping to the mappings to be built. + return new CompositeMapping(mapping, inputMapping, outputMapping); } public static IExistingTargetMapping? TryBuildExistingTargetMapping(MappingBuilderContext ctx) @@ -182,7 +178,7 @@ IExistingTargetMapping existingTargetMapping return null; } - return new CompositeMapping(outputMapping, mapping); + return outputMapping; } private static INewInstanceMapping? TryMapSource(MappingBuilderContext ctx, INewInstanceMapping mapping) @@ -205,6 +201,6 @@ IExistingTargetMapping existingTargetMapping return null; } - return new CompositeMapping(mapping, inputMapping); + return inputMapping; } } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/CompositeMapping.cs b/src/Riok.Mapperly/Descriptors/Mappings/CompositeMapping.cs index cbcbb45651..4555521803 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/CompositeMapping.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/CompositeMapping.cs @@ -3,13 +3,23 @@ namespace Riok.Mapperly.Descriptors.Mappings; /// -/// Creates a composition of two mappings +/// Invokes a named mapping with optional input and output conversions. /// -/// OutputMapping(InnerMapping(source)); +/// OutputMapping(NamedMapping(InputMapping(source))); /// /// -public class CompositeMapping(INewInstanceMapping outerMapping, INewInstanceMapping innerMapping) - : NewInstanceMapping(innerMapping.SourceType, outerMapping.TargetType) +public class CompositeMapping(INewInstanceMapping namedMapping, INewInstanceMapping? inputMapping, INewInstanceMapping? outputMapping) + : NewInstanceMapping(inputMapping?.SourceType ?? namedMapping.SourceType, outputMapping?.TargetType ?? namedMapping.TargetType) { - public override ExpressionSyntax Build(TypeMappingBuildContext ctx) => outerMapping.Build(ctx.WithSource(innerMapping.Build(ctx))); + internal INewInstanceMapping NamedMapping { get; } = namedMapping; + + public override ExpressionSyntax Build(TypeMappingBuildContext ctx) + { + // The input and output conversions do not receive the target value, even if they use [MappingTargetOriginalValue]. + // The target value is passed only to the named mapping. + var conversionCtx = ctx.WithTargetValue(null); + var source = inputMapping?.Build(conversionCtx) ?? ctx.Source; + var result = NamedMapping.Build(ctx.WithSource(source)); + return outputMapping?.Build(conversionCtx.WithSource(result)) ?? result; + } } diff --git a/src/Riok.Mapperly/Descriptors/Mappings/TypeMappingBuildContext.cs b/src/Riok.Mapperly/Descriptors/Mappings/TypeMappingBuildContext.cs index cd8b9fcb29..da7ce21822 100644 --- a/src/Riok.Mapperly/Descriptors/Mappings/TypeMappingBuildContext.cs +++ b/src/Riok.Mapperly/Descriptors/Mappings/TypeMappingBuildContext.cs @@ -58,7 +58,7 @@ private TypeMappingBuildContext( public TypeMappingBuildContext AddIndentation() => new(Source, ReferenceHandler, NameBuilder, SyntaxFactory.AddIndentation(), AdditionalParameters, OriginalTargetValueExpression); - public TypeMappingBuildContext WithTargetValue(ExpressionSyntax targetValue) => + public TypeMappingBuildContext WithTargetValue(ExpressionSyntax? targetValue) => new(Source, ReferenceHandler, NameBuilder, SyntaxFactory, AdditionalParameters, targetValue); /// diff --git a/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs b/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs index f5bccc7af6..b2c0964223 100644 --- a/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs +++ b/src/Riok.Mapperly/Diagnostics/DiagnosticDescriptors.cs @@ -857,6 +857,24 @@ public static class DiagnosticDescriptors isEnabledByDefault: true ); + public static readonly DiagnosticDescriptor MappingTargetOriginalValueTypeMismatch = new( + "RMG101", + "The target member type does not match the [MappingTargetOriginalValue] parameter type", + "The target member {0} cannot be passed to the [MappingTargetOriginalValue] parameter {1} of type {2} in {3}, the default value is used instead", + DiagnosticCategories.Mapper, + DiagnosticSeverity.Warning, + isEnabledByDefault: true + ); + + public static readonly DiagnosticDescriptor MappingTargetOriginalValueMemberNotReadable = new( + "RMG102", + "The target member cannot be read for the [MappingTargetOriginalValue] parameter", + "The target member {0} cannot be read and cannot be passed to the [MappingTargetOriginalValue] parameter {1} in {2}, the default value is used instead", + DiagnosticCategories.Mapper, + DiagnosticSeverity.Warning, + isEnabledByDefault: true + ); + private static string BuildHelpUri(string id) { #if ENV_NEXT diff --git a/test/Riok.Mapperly.Tests/Mapping/UserMethodMappingTargetOriginalValueTest.cs b/test/Riok.Mapperly.Tests/Mapping/UserMethodMappingTargetOriginalValueTest.cs index 031f4f7322..78e14a8b53 100644 --- a/test/Riok.Mapperly.Tests/Mapping/UserMethodMappingTargetOriginalValueTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/UserMethodMappingTargetOriginalValueTest.cs @@ -231,4 +231,260 @@ public Task TargetOriginalValueParameterWithPrivateTargetProperty() return TestHelper.VerifyGenerator(source); } + + [Fact] + public Task NamedMappingForExistingTarget() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(ResolveCount))] + partial void Map(A src, B target); + + [UserMapping(Default = false)] + private static int? ResolveCount(int? value, [MappingTargetOriginalValue] int? original) => value ?? original; + """, + "class A { public int? Value { get; set; } }", + "class B { public int? Count { get; set; } }" + ); + + return TestHelper.VerifyGenerator(source); + } + + [Fact] + public Task NamedMappingForNewInstance() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(ResolveCount))] + partial B Map(A src); + + [UserMapping(Default = false)] + private static int? ResolveCount(int? value, [MappingTargetOriginalValue] int? original) => value ?? original; + """, + "class A { public int? Value { get; set; } }", + "class B { public int? Count { get; set; } = 42; }" + ); + + return TestHelper.VerifyGenerator(source); + } + + [Fact] + public Task NamedMappingFromSourceWithSupertypeParameter() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapPropertyFromSource(nameof(B.Count), Use = nameof(ResolveCount))] + partial void Map(A src, B target); + + private static int? ResolveCount(ICount value, [MappingTargetOriginalValue] int? original) => value.GetCount() ?? original; + """, + "interface ICount { int? GetCount(); }", + "class A : ICount { public int? GetCount() => null; }", + "class B { public int? Count { get; set; } }" + ); + + return TestHelper.VerifyGenerator(source); + } + + [Fact] + public Task NamedMappingWithAdditionalParameter() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(ResolveCount))] + partial B Map(A src, int multiplier); + + private static int? ResolveCount(int? value, int multiplier, [MappingTargetOriginalValue] int? original) + => value * multiplier ?? original; + """, + "class A { public int? Value { get; set; } }", + "class B { public int? Count { get; set; } }" + ); + + return TestHelper.VerifyGenerator(source); + } + + [Fact] + public Task ExternalStaticNamedMapping() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(@Ext.ResolveCount))] + partial void Map(A src, B target); + """, + "class A { public int? Value { get; set; } }", + "class B { public int? Count { get; set; } }", + """ + static class Ext + { + public static int? ResolveCount(int? value, [MappingTargetOriginalValue] int? original) => value ?? original; + } + """ + ); + + return TestHelper.VerifyGenerator(source); + } + + [Fact] + public Task NonInlinedNamedMappingForProjection() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + public static partial IQueryable Project(IQueryable query); + + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(ResolveCount))] + private static partial B Map(A src); + + [UserMapping(Default = false)] + [MapperNoExpressionInlining] + private static int? ResolveCount(int? value, [MappingTargetOriginalValue] int? original) => value ?? original; + """, + "public class A { public int? Value { get; set; } }", + "public record B(int? Count);" + ); + + return TestHelper.VerifyGenerator(source); + } + + [Fact] + public void TargetOriginalValueParameterForNullableTargetPath() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), "Child.Name")] + partial void Map(A src, B target); + + private static string FromOptional(Optional source, [MappingTargetOriginalValue] string original) + => source.Value ?? original; + """, + "class A { public Optional Value { get; set; } = new(); }", + "class B { public C? Child { get; set; } }", + "class C { public string Name { get; set; } = \"\"; }", + "class Optional { public string? Value { get; set; } }" + ); + + TestHelper + .GenerateMapper(source) + .Should() + .HaveSingleMethodBody( + """ + target.Child ??= new global::C(); + target.Child.Name = FromOptional(src.Value, target.Child.Name); + """ + ); + } + + [Fact] + public void NamedMappingForSetOnlyMemberShouldDiagnostic() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(ResolveCount))] + partial void Map(A src, B target); + + [UserMapping(Default = false)] + private static int? ResolveCount(int? value, [MappingTargetOriginalValue] int? original) => value ?? original; + """, + "class A { public int? Value { get; set; } }", + "class B { private int? _count; public int? Count { set => _count = value; } }" + ); + + TestHelper + .GenerateMapper(source, TestHelperOptions.AllowDiagnostics) + .Should() + .HaveDiagnostic( + DiagnosticDescriptors.MappingTargetOriginalValueMemberNotReadable, + "The target member B.Count of type int? cannot be read and cannot be passed to the [MappingTargetOriginalValue] parameter original in ResolveCount, the default value is used instead" + ) + .HaveAssertedAllDiagnostics() + .HaveSingleMethodBody("target.Count = ResolveCount(src.Value, default(int?));"); + } + + [Fact] + public void NamedMappingWithIncompatibleOriginalValueTypeShouldDiagnostic() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(ResolveCount))] + partial void Map(A src, B target); + + [UserMapping(Default = false)] + private static int ResolveCount(string value, [MappingTargetOriginalValue] int original) => value.Length + original; + """, + "class A { public string Value { get; set; } = \"\"; }", + "class B { public long Count { get; set; } }" + ); + + TestHelper + .GenerateMapper(source, TestHelperOptions.AllowDiagnostics) + .Should() + .HaveDiagnostic( + DiagnosticDescriptors.ReferencedMappingTargetTypeMismatch, + "The target type int of the referenced mapping ResolveCount does not match the expected type long" + ) + .HaveDiagnostic( + DiagnosticDescriptors.MappingTargetOriginalValueTypeMismatch, + "The target member B.Count of type long cannot be passed to the [MappingTargetOriginalValue] parameter original of type int in ResolveCount, the default value is used instead" + ) + .HaveAssertedAllDiagnostics() + .HaveSingleMethodBody("target.Count = (long)ResolveCount(src.Value, default(int));"); + } + + [Fact] + public void IncompatibleOriginalValueTypeForInitOnlyMemberShouldNotDiagnostic() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + partial B Map(A src); + + private static long FromOptional(Optional source, [MappingTargetOriginalValue] int original) + => source.HasValue ? source.Value : original; + """, + "class A { public Optional Count { get; set; } }", + "class B { public long Count { get; init; } }", + "struct Optional { public bool HasValue { get; } public long Value { get; } }" + ); + + TestHelper + .GenerateMapper(source) + .Should() + .HaveSingleMethodBody( + """ + var target = new global::B() + { + Count = FromOptional(src.Count, default(int)), + }; + return target; + """ + ); + } + + [Fact] + public void NamedMappingShouldNotPassOriginalValueToSourceConversion() + { + var source = TestSourceBuilder.MapperWithBodyAndTypes( + """ + [MapProperty(nameof(A.Value), nameof(B.Count), Use = nameof(ResolveCount))] + partial void Map(A src, B target); + + [UserMapping(Default = false)] + private static int ResolveCount(Wrapper value, [MappingTargetOriginalValue] int original) => value.Count + original; + + private static Wrapper ToWrapper(string value, [MappingTargetOriginalValue] Wrapper original) => original; + """, + "class A { public string Value { get; set; } = \"\"; }", + "class B { public int Count { get; set; } }", + "class Wrapper { public int Count { get; set; } }" + ); + + TestHelper + .GenerateMapper(source, TestHelperOptions.AllowDiagnostics) + .Should() + .HaveDiagnostic( + DiagnosticDescriptors.ReferencedMappingSourceTypeMismatch, + "The source type Wrapper of the referenced mapping ResolveCount does not match the expected type string" + ) + .HaveAssertedAllDiagnostics() + .HaveSingleMethodBody("target.Count = ResolveCount(ToWrapper(src.Value, default(global::Wrapper)), target.Count);"); + } } diff --git a/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.ExternalStaticNamedMapping#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.ExternalStaticNamedMapping#Mapper.g.verified.cs new file mode 100644 index 0000000000..33f17b69d3 --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.ExternalStaticNamedMapping#Mapper.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + partial void Map(global::A src, global::B target) + { + target.Count = global::Ext.ResolveCount(src.Value, target.Count); + } +} \ No newline at end of file diff --git a/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForExistingTarget#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForExistingTarget#Mapper.g.verified.cs new file mode 100644 index 0000000000..bab2e6aeab --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForExistingTarget#Mapper.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + partial void Map(global::A src, global::B target) + { + target.Count = ResolveCount(src.Value, target.Count); + } +} \ No newline at end of file diff --git a/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForNewInstance#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForNewInstance#Mapper.g.verified.cs new file mode 100644 index 0000000000..f8a8ea3c28 --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingForNewInstance#Mapper.g.verified.cs @@ -0,0 +1,13 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + partial global::B Map(global::A src) + { + var target = new global::B(); + target.Count = ResolveCount(src.Value, target.Count); + return target; + } +} \ No newline at end of file diff --git a/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingFromSourceWithSupertypeParameter#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingFromSourceWithSupertypeParameter#Mapper.g.verified.cs new file mode 100644 index 0000000000..63d490cc68 --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingFromSourceWithSupertypeParameter#Mapper.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + partial void Map(global::A src, global::B target) + { + target.Count = ResolveCount((global::ICount)src, target.Count); + } +} \ No newline at end of file diff --git a/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingWithAdditionalParameter#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingWithAdditionalParameter#Mapper.g.verified.cs new file mode 100644 index 0000000000..7c31d9acf8 --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NamedMappingWithAdditionalParameter#Mapper.g.verified.cs @@ -0,0 +1,13 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + partial global::B Map(global::A src, int multiplier) + { + var target = new global::B(); + target.Count = ResolveCount(src.Value, multiplier, target.Count); + return target; + } +} \ No newline at end of file diff --git a/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NonInlinedNamedMappingForProjection#Mapper.g.verified.cs b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NonInlinedNamedMappingForProjection#Mapper.g.verified.cs new file mode 100644 index 0000000000..67b77fd5e3 --- /dev/null +++ b/test/Riok.Mapperly.Tests/_snapshots/UserMethodMappingTargetOriginalValueTest.NonInlinedNamedMappingForProjection#Mapper.g.verified.cs @@ -0,0 +1,20 @@ +//HintName: Mapper.g.cs +// +#nullable enable +public partial class Mapper +{ + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + public static partial global::System.Linq.IQueryable Project(global::System.Linq.IQueryable query) + { +#nullable disable + return global::System.Linq.Queryable.Select(query, x => new global::B(ResolveCount(x.Value, default(int?)))); +#nullable enable + } + + [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "0.0.1.0")] + private static partial global::B Map(global::A src) + { + var target = new global::B(ResolveCount(src.Value, default(int?))); + return target; + } +} \ No newline at end of file