mapperly icon indicating copy to clipboard operation
mapperly copied to clipboard

Add OnlyExplicitMappedMembers implementation

Open Kataane opened this issue 3 months ago • 0 comments

Add OnlyExplicitMappedMembers Configuration Option

Description

First, I want to express my gratitude for the beautiful library and the excellent work that has been done in Mapperly. This library has been incredibly useful!

This PR introduces a new OnlyExplicitMappedMembers configuration option to the MapperAttribute that allows mapping only properties with explicit configurations (via attributes like MapProperty). All other properties will be ignored by default when this option is enabled.

This feature is particularly useful when working with classes that have many properties but you only need to map a few specific ones, providing a more declarative and maintainable approach compared to explicitly ignoring every unwanted property.

Changes made:

  • Added OnlyExplicitMappedMembers property to MapperAttribute
  • Added corresponding configuration to MapperConfiguration and merger logic
  • Implemented the ignore logic in IgnoredMembersBuilder to automatically ignore non-matching members when this option is enabled
  • Added comprehensive unit tests covering different scenarios (extra source members, extra target members, and extra members in both)
  • Updated test infrastructure to support the new configuration option

Fixes #1981

Checklist

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

Kataane avatar Oct 23 '25 19:10 Kataane