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

Support existing target mappings with named mappings (MapProperty.Use) #1649

Open
latonz opened this issue Dec 19, 2024 · 0 comments · May be fixed by #1720
Open

Support existing target mappings with named mappings (MapProperty.Use) #1649

latonz opened this issue Dec 19, 2024 · 0 comments · May be fixed by #1720
Labels
enhancement New feature or request

Comments

@latonz
Copy link
Contributor

latonz commented Dec 19, 2024

Mapperly should support MapProperty.Use on mappings which target an existing instance.

Sample Test
    [Fact]
    public Task ShouldUseReferencedMappingOnSelectedPropertiesWithExistingInstance()
    {
        var source = TestSourceBuilder.MapperWithBodyAndTypes(
            """
            [MapProperty(nameof(A.Values1), nameof(B.Values1), Use = nameof(MapV1)]
            [MapProperty(nameof(A.Values2), nameof(B.Values2), Use = nameof(MapV2)]
            public partial B Map(A source);

            [UserMapping(Default = true)]
            private void DefaultMapping(List<string> source, List<string> target) {}
            private void MapV1(List<string> source, List<string> target) {}
            private void MapV2(List<string> source, List<string> target) {}
            """,
            """
            class A
            {
                public List<string> Values { get; } = [];
                public List<string> Values1 { get; } = [];
                public List<string> Values2 { get; } = [];
            }
            """,
            """
            class B
            {
                public List<string> Values { get; } = [];
                public List<string> Values1 { get; } = [];
                public List<string> Values2 { get; } = [];
            }
            """
        );
        return TestHelper.VerifyGenerator(source);
    }

See #1648 (comment)

@latonz latonz added the enhancement New feature or request label Dec 19, 2024
@clegoz clegoz linked a pull request Feb 15, 2025 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant