-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support partial static methods in non-static classes
- Loading branch information
Showing
14 changed files
with
311 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/Riok.Mapperly.IntegrationTests/Dto/ITestStaticInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Riok.Mapperly.IntegrationTests.Dto | ||
{ | ||
public interface ITestStaticInterface | ||
{ | ||
#if NET7_0_OR_GREATER | ||
static abstract int StaticAbstractDirectInt(int value); | ||
#endif | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/Riok.Mapperly.IntegrationTests/Mapper/TestMapperWithStaticMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Riok.Mapperly.Abstractions; | ||
using Riok.Mapperly.IntegrationTests.Dto; | ||
|
||
namespace Riok.Mapperly.IntegrationTests.Mapper | ||
{ | ||
[Mapper] | ||
public partial class TestMapperWithStaticMethods : ITestStaticInterface | ||
{ | ||
public static partial double DirectDouble(double value); | ||
|
||
public static partial int StaticAbstractDirectInt(int value); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
test/Riok.Mapperly.IntegrationTests/TestMapperWithStaticMethodsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Threading.Tasks; | ||
using Riok.Mapperly.IntegrationTests.Dto; | ||
using Riok.Mapperly.IntegrationTests.Helpers; | ||
using Riok.Mapperly.IntegrationTests.Mapper; | ||
using VerifyXunit; | ||
using Xunit; | ||
|
||
namespace Riok.Mapperly.IntegrationTests | ||
{ | ||
[UsesVerify] | ||
public class TestMapperWithStaticMethodsTest : BaseMapperTest | ||
{ | ||
[Fact] | ||
[VersionedSnapshot(Versions.NET6_0 | Versions.NET7_0)] | ||
public Task SnapshotGeneratedSource() | ||
{ | ||
var path = GetGeneratedMapperFilePath(nameof(TestMapperWithStaticMethods)); | ||
return Verifier.VerifyFile(path); | ||
} | ||
|
||
[Theory | ||
#if !NET7_0_OR_GREATER | ||
(Skip = "Requires language version '11.0' or greater") | ||
#endif | ||
] | ||
[InlineData(8)] | ||
[InlineData(12)] | ||
public void CallStaticInterfaceMemberShouldWork(int value) | ||
{ | ||
Assert.Equal(value, GenericMethod<TestMapperWithStaticMethods>(value)); | ||
|
||
static int GenericMethod<T>(int value) | ||
where T : ITestStaticInterface | ||
{ | ||
#if NET7_0_OR_GREATER | ||
return T.StaticAbstractDirectInt(value); | ||
#else | ||
// It's intentional "wrong" value, it's here only to return something | ||
return 0; | ||
#endif | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ationTests/_snapshots/TestMapperWithStaticMethodsTest.SnapshotGeneratedSource.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// <auto-generated /> | ||
#nullable enable | ||
namespace Riok.Mapperly.IntegrationTests.Mapper | ||
{ | ||
public partial class TestMapperWithStaticMethods | ||
{ | ||
public static partial double DirectDouble(double value) | ||
{ | ||
return value; | ||
} | ||
|
||
public static partial int StaticAbstractDirectInt(int value) | ||
{ | ||
return value; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...sts/_snapshots/TestMapperWithStaticMethodsTest.SnapshotGeneratedSource_NET6_0.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// <auto-generated /> | ||
#nullable enable | ||
namespace Riok.Mapperly.IntegrationTests.Mapper | ||
{ | ||
public partial class TestMapperWithStaticMethods | ||
{ | ||
public static partial double DirectDouble(double value) | ||
{ | ||
return value; | ||
} | ||
|
||
public static partial int StaticAbstractDirectInt(int value) | ||
{ | ||
return value; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...sts/_snapshots/TestMapperWithStaticMethodsTest.SnapshotGeneratedSource_NET7_0.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// <auto-generated /> | ||
#nullable enable | ||
namespace Riok.Mapperly.IntegrationTests.Mapper | ||
{ | ||
public partial class TestMapperWithStaticMethods | ||
{ | ||
public static partial double DirectDouble(double value) | ||
{ | ||
return value; | ||
} | ||
|
||
public static partial int StaticAbstractDirectInt(int value) | ||
{ | ||
return value; | ||
} | ||
} | ||
} |
Oops, something went wrong.