-
-
Notifications
You must be signed in to change notification settings - Fork 141
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: add IgnoreObsoleteMembers and MapProperty
maps ignored Target
#392
Conversation
Does Mapperly support ignoring nested properties? // Where ProducerDto has getter setter methods and a parameterless constructor.
[MapperIgnoreSource("Manufacturer.Id")]
[MapperIgnoreTarget("Producer.Id")]
[MapProperty(nameof(Car.Manufacturer), nameof(CarDto.Producer))] // Map property with a different name in the target type
public static partial CarDto MapCarToDto(Car car); Generates public static partial global::Riok.Mapperly.Sample.CarDto MapCarToDto(global::Riok.Mapperly.Sample.Car car)
{
var target = new global::Riok.Mapperly.Sample.CarDto();
if (car.Manufacturer != null)
{
target.Producer = MapToProducerDto(car.Manufacturer);
}
target.Name = car.Name;
//...
private static global::Riok.Mapperly.Sample.ProducerDto MapToProducerDto(global::Riok.Mapperly.Sample.Manufacturer source)
{
var target = new global::Riok.Mapperly.Sample.ProducerDto();
target.Id = source.Id;
target.Name = source.Name;
return target;
} |
@TimothyMakkison nested ignored properties are currently not supported. Is there a use-case for this? |
Mb I thought it did, wasn't sure if i had messed up the member paths. I wanted to reuse some of the logic to let explicit mappings override ignored deprecated members. I think nested ignores would be a good addition to mapperl, It already has nested explicit mappings. |
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 🌞
- Good looking tests 😊
- Could you also update the documentation?
- TBD: Should obsolete enum members also be ignored (to be discussed, if implemented, implement it in another PR). Should it be automatically or via a separate configuration? I think the best way would be to do it the exact same way, without any additional configuration. If it should be overwritten for an enum, it could get overwritten on an enum mapping method with the same attribute. WDYT?
src/Riok.Mapperly.Abstractions/MapperIgnoreObsoleteMembersAttribute.cs
Outdated
Show resolved
Hide resolved
...Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersMappingBuilderContext.cs
Outdated
Show resolved
Hide resolved
...Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersMappingBuilderContext.cs
Outdated
Show resolved
Hide resolved
...Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersMappingBuilderContext.cs
Outdated
Show resolved
Hide resolved
Mapperly doesn't really have nested mappings, it does only have flattening/unflattening. |
src/Riok.Mapperly.Abstractions/MapperIgnoreObsoleteMembersAttribute.cs
Outdated
Show resolved
Hide resolved
@TimothyMakkison FYI: an issue to the nested ignored properties just got opened: #395 |
@TimothyMakkison feel free to re-request a review when ready 😊 |
Discovered #450 when trying to implement this. I could fix the bug so |
|
cc38119
to
0d96703
Compare
Codecov Report
@@ Coverage Diff @@
## main #392 +/- ##
==========================================
+ Coverage 91.04% 92.24% +1.20%
==========================================
Files 166 151 -15
Lines 5627 4851 -776
Branches 711 618 -93
==========================================
- Hits 5123 4475 -648
+ Misses 351 256 -95
+ Partials 153 120 -33
... and 61 files with indirect coverage changes 📣 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 the updates, I added my feedback.
Could you also update the documentation (I would add a new section in 01-mapper.md
in ## Properties / fields
).
...Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersMappingBuilderContext.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewInstanceObjectMemberMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/ObjectMemberMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
49683c1
to
e99c604
Compare
Note that in order to support Now if a target is Ignored but is explicitly mapped with |
14d3598
to
6e6a6b5
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.
I'd add a warning diagnostic if an explicit ignored property is mapped manually (but not if a property is ignored because it is obsolete). I think this could be done in another PR.
Could you adjust the PR body that it resolves #450?
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/NewInstanceObjectMemberMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Riok.Mapperly/Descriptors/MappingBodyBuilders/ObjectMemberMappingBodyBuilder.cs
Outdated
Show resolved
Hide resolved
MapProperty
maps ignored Target
b27c01b
to
d5f6b0d
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.
@TimothyMakkison I created #512 to implement the diagnostic.
Whats still missing:
- Update the documentation (I would add a new section in
01-mapper.md
in## Properties / fields
) - Update integration tests
Otherwise this MR looks good 😊
...Riok.Mapperly/Descriptors/MappingBodyBuilders/BuilderContext/MembersMappingBuilderContext.cs
Outdated
Show resolved
Hide resolved
640097c
to
e7525be
Compare
6d22999
to
0fa9690
Compare
@TimothyMakkison looks good to me. A few linter issues need to be fixed... |
Thanks, please don't merge this just yet, I haven't added the integration tests |
Oh thanks, I would have missed that 🙈 |
65100f3
to
62b4e39
Compare
62b4e39
to
9ad8722
Compare
🎉 This PR is included in version 2.9.0-next.3 🎉 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 📦🚀 |
Resolves #284 and #450.
MapperIgnoreObsoleteMembersAttribute
and addedIgnoreObsoleteStrategy
toMapperAttribute
. UpdatedMembersMappingBuilderContext
to add the derecated members to there respectiveIgnored*MemberNames
.FieldMember
andPropertyMember
to expose the underlying symbol.IgnoreObsoleteStrategy
is none so deprecated members are treated as normal.Both
Haven't done this yet, I'm not 100% sure how
MemberConfigsByRootTargetName
works to match the obsolete members to the respective explicitly mapped member.I'll wait for #390 and then update the relevant logic.