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

Collection property with init setter is not mapped #664

Closed
cremor opened this issue Aug 21, 2023 · 1 comment · Fixed by #1190
Closed

Collection property with init setter is not mapped #664

cremor opened this issue Aug 21, 2023 · 1 comment · Fixed by #1190
Labels
bug Something isn't working released on @next

Comments

@cremor
Copy link

cremor commented Aug 21, 2023

Describe the bug
I have a working "existing target object" (void method) mapper for a type that contains a collection property. If I change the collection property to an init setter then the collection is not mapped any more. That makes no sense because it is mapped with a private setter or with no setter at all. So an init setter should also work.

To Reproduce
Steps to reproduce the behavior:

  1. Paste the code from below.
  2. Check the generated code. Notice that the collection is mapped.
  3. Modify the commented line to have an init setter.
  4. Notice that the collection is not mapped any more.
  5. Notice that the message "RMG015 Cannot map from member Source.Subs of type ICollection to init only member path Target.Subs of type ICollection" is shown.
  6. Change the property setter to private set. Notice that the collection is mapped again.
  7. Even weirder: Change the property setter to private init and notice that it is also mapped. Only public init isn't.

Expected behavior
init collection properties should be mapped just like private set (or private init) properties and properties without any setter are mapped.

Code snippets

public class Source
{
    public required ICollection<SourceSub> Subs { get; init; }
}

public class SourceSub
{
    public required string Name { get; init; }
}

public class Target
{
    // Change this to an 'init' setter to reproduce.
    public ICollection<TargetSub> Subs { get; } = new List<TargetSub>();
}

public class TargetSub
{
    public required string Name { get; set; }
}

[Mapper]
public static partial class Mapper
{
    public static partial void MapToEntity(Source source, Target target);
}

Environment (please complete the following information):

  • Mapperly Version: 3.1.0
  • .NET Version: 7.0.400
  • Target Framework: net7.0
  • IDE: Visual Studio 2022 17.7.1
  • OS: Windows 10
Copy link

🎉 This issue has been resolved in version 3.5.0-next.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released on @next
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants