You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
It seems like Mapperly currently uses the target property setter visibility in an "existing target object" mapper (void method) to decide if a collection (ICollection<T>) is completely replaced or if the items in the collection are just added. This is confusing/dangerous because a simple visiblity change on the setter can lead to different behavior of the mapper.
Describe the solution you'd like
I'd like to configure if items are added to an existing collection or if a collection is replaced. One of the two possibilities should be the default for all collection properties, regardless of their setter visibility.
If the currently active setting is to replace the collection, but the target property has no visible setter, then the generated code should call Clear() on the collection before adding the items.
Describe alternatives you've considered
I know that I can call Clear() in a "before map" method. But the main problem here is that I might not even notice that I have to do this until I get a runtime bug.
Additional context
In theory this also affects mappers that return the mapped object, but that would only show a difference if the constructor/object factory already adds items to the collection.
The text was updated successfully, but these errors were encountered:
Maybe it would even be possible to create a "merge" option? That might have a higher complexity to implement, but could also be useful. I assume that would require either a way to specify which property is compared for the equals check, or user provided methods for the equals check.
Is your feature request related to a problem? Please describe.
It seems like Mapperly currently uses the target property setter visibility in an "existing target object" mapper (void method) to decide if a collection (
ICollection<T>
) is completely replaced or if the items in the collection are just added. This is confusing/dangerous because a simple visiblity change on the setter can lead to different behavior of the mapper.Describe the solution you'd like
I'd like to configure if items are added to an existing collection or if a collection is replaced. One of the two possibilities should be the default for all collection properties, regardless of their setter visibility.
If the currently active setting is to replace the collection, but the target property has no visible setter, then the generated code should call
Clear()
on the collection before adding the items.Describe alternatives you've considered
I know that I can call
Clear()
in a "before map" method. But the main problem here is that I might not even notice that I have to do this until I get a runtime bug.Additional context
In theory this also affects mappers that return the mapped object, but that would only show a difference if the constructor/object factory already adds items to the collection.
The text was updated successfully, but these errors were encountered: