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
feat: added tuple mapping support #467
Conversation
Codecov Report
@@ Coverage Diff @@
## main #467 +/- ##
==========================================
- Coverage 91.09% 90.59% -0.51%
==========================================
Files 167 173 +6
Lines 5660 5921 +261
Branches 717 757 +40
==========================================
+ Hits 5156 5364 +208
- Misses 351 397 +46
- Partials 153 160 +7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for another great contribution!
I added my comments 😊 Overall it looks really really good 💪 Super happy with your valuable contributions 😊
I'd prefer the more verbose style (A: source.C, B: source.D)
for named tuples as this could improve the readability of the generated code and is also aligned with the generated code for property initializers where Mapperly always generates explicit value assignments.
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewTupleExpressionMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBuilders/ExplicitCastMappingBuilder.cs
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewTupleExpressionMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewTupleExpressionMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewTupleExpressionMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/TupleConstructorParameterMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewTupleExpressionMapping.cs
Outdated
Show resolved
Hide resolved
...Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/INewTupleExpressionBuilderContext.cs
Outdated
Show resolved
Hide resolved
...Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/INewTupleExpressionBuilderContext.cs
Outdated
Show resolved
Hide resolved
....Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/NewTupleExpressionBuilderContext.cs
Outdated
Show resolved
Hide resolved
Thanks for the review 🙏 I'll squash the commits and faff around with the integration tests when you're happy with these changes 👍 |
Looks good to me 😊 |
Weird, I wonder why they never added this. I've hackily added I added Should I instead create |
@TimothyMakkison I think separating the two mappings makes the code easier to read, therefore I'd separate them as |
fb32535
to
43ce94e
Compare
Should be ready to merge 👍
I wonder if it's possible to configure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates. Few smaller comments...
VerifyTests has awesome plugins to view the diff, see VerifyTests supported tools, for example Rider Verify Tests Support.
Whats still missing is a new MappingConversionType
, please also update the docs (14-conversions.md
).
src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBuilders/NewInstanceObjectPropertyMappingBuilder.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
This PR is near completion. I've added support for I have experimented with making tuple methods either directly return the tuple if it doesn't map to any child members, or use |
831c4a1
to
615c8ff
Compare
Draft until I double check this |
5e9b0c3
to
d77aa2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates.
Added a few smaller feedbacks...
Regarding the inlined method mapping: For now I'd keep it simple and always generate a method for a tuple expression mapping. The compiler will probably inline it anyway. If we come to the conclusion it is worth to inline these one-liner methods, IMO we should do so in a separate PR, which could probably also affect other method mappings and maybe even be handled on a MethodMapping
level.
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
...erly/Descriptors/MappingBodyBuilders/BuilderContext/NewValueTupleExpressionBuilderContext.cs
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewValueTupleMappingBodyBuilder.cs
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/ValueTupleConstructorParameterMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleConstructorMapping.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/Mappings/NewValueTupleExpressionMapping.cs
Outdated
Show resolved
Hide resolved
Thanks will make the changes later. 👍
I'm already using a slightly hacky way of method inlining. Do you want me to remove it? |
@TimothyMakkison I reviewed it, I'd remove it for now, but keep this commit somewhere. We can probably reintroduce a similar concept in another PR on the MethodMapping level in a later version of Mapperly. |
620e11e
to
3eee96d
Compare
Thanks for the review, I've removed method inlining and performed your suggested changes. I'm converting this pr to a draft until I proof read it. |
d384b57
to
ff2463a
Compare
🎉 This PR is included in version 2.9.0-next.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 3.0.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Description
Fixes #448 Added support for tuple mapping, supported mapping attributes and repeat member mappings are no longer created.
Class -> Tuple
andTuple -> Class
will map via field names, or if a field doesn't have a name its default positional name is used.Tuple
toTuple
will try to map via field names, otherwise it will attempt to match fields by position.IgnoreSource
,IgnoreProperty
andMapProperty
.IgnoreSource
andMapProperty
will only use field names when available, otherwise if the field doesn't have a name it will use the default positional name.Question: currently a simple tuple expression is used, should the targets field names be added?
I'll update the integration test when we decide on this behaviour