Skip to content

Commit

Permalink
fix: extension method parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Nov 20, 2023
1 parent 572a04a commit 60dc83f
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;
}
}

0 comments on commit 60dc83f

Please sign in to comment.