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

Include all members from a nested member #453

Closed
latonz opened this issue May 22, 2023 · 10 comments · Fixed by #1245
Closed

Include all members from a nested member #453

latonz opened this issue May 22, 2023 · 10 comments · Fixed by #1245
Labels
enhancement New feature or request

Comments

@latonz
Copy link
Contributor

latonz commented May 22, 2023

If a class has a nested member which is flattened without the member name prefix, each member needs a manual MapProperty attribute to be mapped correctly. This could be simplified a lot by including all members of a nested property by one configuration attribute.
Name proposal: MapNestedPropertiesAttribute(string memberName)
(probably MapNestedMembersAttribute would be better as this includes fields and does not only apply to properties, but for backward compatibility MapProperty is called what it is, therefore the name should match).

Example:

class Document { string Name; DocumentSettings Settings;}
class DocumentSettings { string Locale; string CurrencySymbol; }
class DocumentDto { string Name; string Locale; string CurrencySymbol; }

[Mapper]
partial class Mapper
{
    [MapNestedProperties(nameof(Document.Settings))]
    public partial DocumentDto Map(Document doc);
    
    // instead of:
    [MapProperty("Settings.Locale", "Locale")]
    [MapProperty("Settings.CurrencySymbol", "CurrencySymbol")]
    public partial DocumentDto Map(Document doc);
}

AutoMapper supports this via IncludeMembers.
See #447 (reply in thread).

@latonz latonz added the enhancement New feature or request label May 22, 2023
@TimothyMakkison
Copy link
Collaborator

How should it be used for other mappings? ie should it map Document.Settings.Locale -> DocumentDto.SettingsLocale

@latonz
Copy link
Contributor Author

latonz commented Jun 9, 2023

@TimothyMakkison good question, didn't thought about this. I think this should diagnostic unless explicitly mapped.

@TimothyMakkison
Copy link
Collaborator

Should it support nested members? Something like:

[Mapper]
partial class Mapper
{
    [MapNestedProperties("Settings.Region"))]
    public partial DocumentDto Map(Document doc);
    
    // instead of:
    [MapProperty("Settings.Locale", "Locale")]
    [MapProperty("Settings.CurrencySymbol", "CurrencySymbol")]
    public partial DocumentDto Map(Document doc);
}

@latonz
Copy link
Contributor Author

latonz commented Jun 14, 2023

@TimothyMakkison intuitively I'd say it should support nested members.

@latonz latonz linked a pull request Jul 27, 2023 that will close this issue
7 tasks
@latonz latonz added this to the v2.10.0 milestone Jul 27, 2023
@latonz latonz removed this from the v3.1.0 milestone Sep 28, 2023
@trejjam
Copy link
Contributor

trejjam commented Dec 13, 2023

I am interested in this feature. Can I help?

@TimothyMakkison
Copy link
Collaborator

Checkout #598, looks like they tried to add this feature but never completed it

@mindotale
Copy link

Hi, what is the progress on this issue? This is a really useful and necessary feature.

@latonz
Copy link
Contributor Author

latonz commented Mar 27, 2024

@mindotale nothing new, there was an PR #587 by @zeidoo which was never completed.
We do have this feature on our roadmap, but it currently isn‘t high priority. If it is for you, feel free to contribute or alternatively you could sponsor the project / this feature 😉

rhodon-jargon pushed a commit to rhodon-jargon/mapperly that referenced this issue Apr 22, 2024
rhodon-jargon pushed a commit to rhodon-jargon/mapperly that referenced this issue Apr 22, 2024
latonz pushed a commit to rhodon-jargon/mapperly that referenced this issue Apr 29, 2024
Copy link

github-actions bot commented May 3, 2024

🎉 This issue has been resolved in version 3.6.0-next.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

🎉 This issue has been resolved in version 3.6.0 🎉

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
enhancement New feature or request
Projects
None yet
4 participants