Add OnlyExplicitMappedMembers Configuration Option#2261
Open
Add OnlyExplicitMappedMembers Configuration Option#2261
Conversation
- Fix ignore logic to exclude all members not in explicit mappings (MapProperty/MapPropertyFromSource), not just those missing from the opposite type - Add tests with explicit [MapProperty] and [MapPropertyFromSource] attributes - Use <see cref> tag for MapPropertyAttribute in XML doc comment
Contributor
Author
|
ref to old #2001 |
latonz
requested changes
May 5, 2026
Contributor
latonz
left a comment
There was a problem hiding this comment.
Thank you for this contribution.
- please update the docs
- add a test combining
OnlyExplicitMappedMembersandRequiredMapping - add a test combining
IgnoreObsoleteMembersandRequiredMapping
|
|
||
| if (ctx.Configuration.Mapper.OnlyExplicitMappedMembers) | ||
| { | ||
| var explicitlyMappedMembers = ctx.Configuration.Members.GetMembersWithExplicitConfigurations(sourceTarget).ToHashSet(); |
Contributor
There was a problem hiding this comment.
MapNestedPropertiesAttribute also need to be considered… Also add a test for this.
Could probably be included in GetMembersWithExplicitConfigurations.
| public bool AutoUserMappings { get; set; } = true; | ||
|
|
||
| /// <summary> | ||
| /// When set to <c>true</c>, only properties with explicit configurations (via attributes like <see cref="MapPropertyAttribute"/>) |
Contributor
There was a problem hiding this comment.
Mapperly also maps fields, use members instead of properties.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
OnlyExplicitMappedMembersconfiguration option to theMapperAttributethat allows mapping only properties with explicit configurations (via attributes likeMapProperty). 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:
OnlyExplicitMappedMembersproperty toMapperAttributeMapperConfigurationand merger logicIgnoredMembersBuilderto automatically ignore non-matching members when this option is enabledFixes #1981
Checklist