Skip to content

Conversation

@samusaran
Copy link

@samusaran samusaran commented Jan 16, 2026

Add support for Shallow Cloning

Description

The current behaviour of Mapperly when mapping between same types is either to return the original instance, or to perform a deep clone of the entire object graph.

Another use case lies in the middle of those two solutions: Shallow Cloning.

Shallow cloning an object allows a user to clone an object at the first level, while keeping all the references to other reference types unchanged. If a user needs some references to be handled differently, they can still use a user mapping on those specific properties.

This feature also aligns to the default behaviour of Automapper, and this could help users to more easily migrate from Automapper to Mapperly.

Fixes #2113

Checklist

  • The existing code style is followed
  • The commit message follows our guidelines
  • Performed a self-review of my code
  • Hard-to-understand areas of my code are commented
  • The documentation is updated (as applicable)
  • Unit tests are added/updated
  • Integration tests are added/updated (as applicable, especially if feature/bug depends on roslyn or framework version in use)

@samusaran
Copy link
Author

@latonz I would continue the discussion here.

As stated in the github issue #2117, another solution would be to deprecate UseShallowCloning in favour of a single CloningBehaviour enum, to avoid having conflicting configuration between shallow and deep cloning.

At least from a user perspective, I find this solution to be less confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Give the possibility to clone objects without UseDeepCloning

1 participant