Skip to content

Commit

Permalink
Add UseStaticGenericMapperStaticMethod, IgnoreInstanceMethodFromStati…
Browse files Browse the repository at this point in the history
…cMapper
  • Loading branch information
trejjam committed Nov 13, 2023
1 parent 44ac9ff commit 3f907b4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,63 @@ class B { public string StringValue { get; set; } }
return TestHelper.VerifyGenerator(source);
}

[Fact]
public Task UseStaticGenericMapperStaticMethod()
{
var source = TestSourceBuilder.CSharp(
"""
using Riok.Mapperly.Abstractions;
record A(AExternal Value);
record B(BExternal Value);
record AExternal();
record BExternal();
class OtherMapper {
public static BExternal ToBExternal(AExternal source) => new BExternal();
}
[Mapper]
[UseStaticMapper<OtherMapper>]
public partial class Mapper
{
static partial B Map(A source);
}
"""
);

return TestHelper.VerifyGenerator(source);
}

[Fact]
public Task IgnoreInstanceMethodFromStaticMapper()
{
var source = TestSourceBuilder.CSharp(
"""
using Riok.Mapperly.Abstractions;
using Riok.Mapperly.Abstractions.ReferenceHandling;
record A(AExternal Value);
record B(BExternal Value);
record AExternal();
record BExternal();
class OtherMapper {
public BExternal ToBExternal(AExternal source) => new BExternal();
}
[Mapper]
[UseStaticMapper<OtherMapper>]
public partial class Mapper
{
static partial B Map(A source);
}
"""
);

return TestHelper.VerifyGenerator(source);
}

[Fact]
public void MixedStaticMethodWithPartialInstanceMethod()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
public partial class Mapper
{
static partial global::B Map(global::A source)
{
var target = new global::B(MapToBExternal(source.Value));
return target;
}

private static global::BExternal MapToBExternal(global::AExternal source)
{
var target = new global::BExternal();
return target;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//HintName: Mapper.g.cs
// <auto-generated />
#nullable enable
public partial class Mapper
{
static partial global::B Map(global::A source)
{
var target = new global::B(global::OtherMapper.ToBExternal(source.Value));
return target;
}
}

0 comments on commit 3f907b4

Please sign in to comment.