Skip to content

Commit

Permalink
fix: extension method parameters for existing target mappings (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam authored Nov 20, 2023
1 parent 3e5ed87 commit 86408ce
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static ParameterListSyntax ParameterList(bool extensionMethod, params Met
.WhereNotNull()
.DistinctBy(x => x.Ordinal)
.OrderBy(x => x.Ordinal)
.Select(p => Parameter(extensionMethod, p));
.Select((p, i) => Parameter(extensionMethod && i == 0, p));
return SyntaxFactory.ParameterList(CommaSeparatedList(parameterSyntaxes));
}

Expand Down
29 changes: 29 additions & 0 deletions test/Riok.Mapperly.Tests/Mapping/ExtensionMethodTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Riok.Mapperly.Tests.Mapping;

[UsesVerify]
public class ExtensionMethodTest
{
[Fact]
public Task ExtensionMapMethodShouldWork()
{
var source = TestSourceBuilder.MapperWithBodyAndTypes(
"static partial B MapToB(this A source);",
"class A { public int Value { get; set; } }",
"class B { public int Value { get; set; } }"
);

return TestHelper.VerifyGenerator(source);
}

[Fact]
public Task ExtensionUpdateMethodShouldWork()
{
var source = TestSourceBuilder.MapperWithBodyAndTypes(
"static partial void MapToB(this A source, B target);",
"class A { public int Value { get; set; } }",
"class B { public int Value { get; set; } }"
);

return TestHelper.VerifyGenerator(source);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
public partial class Mapper
{
static partial global::B MapToB(this global::A source)
{
var target = new global::B();
target.Value = source.Value;
return target;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
public partial class Mapper
{
static partial void MapToB(this global::A source, global::B target)
{
target.Value = source.Value;
}
}

1 comment on commit 86408ce

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'SourceGeneratorBenchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 86408ce Previous: 1584799 Ratio
Riok.Mapperly.Benchmarks.SourceGeneratorBenchmarks.Compile 1056186.494603737 ns (± 128084.18180303885) 121785.33090444711 ns (± 503.2236580394965) 8.67
Riok.Mapperly.Benchmarks.SourceGeneratorBenchmarks.LargeCompile 27317760.004464287 ns (± 199329.46088073996) 1011824.0924479166 ns (± 8624.974365186443) 27.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.