Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: extension method parameters for existing target mappings #923

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading