feat: Add SnakeCase strategy to PropertyNameMappingStrategy#2011
Merged
feat: Add SnakeCase strategy to PropertyNameMappingStrategy#2011
Conversation
Contributor
|
Please also update the documentation. |
Contributor
Author
|
Hi @latonz, |
latonz
requested changes
Dec 9, 2025
test/Riok.Mapperly.Tests/Descriptors/MemberPathCandidateBuilderTest.cs
Outdated
Show resolved
Hide resolved
Contributor
Author
|
Hi @latonz, Thank you for your review. I fixed the issues based on your reviews. The main point that is still unresolved is the complex login in MemberPathCandidateBuilder.cs. |
c2e1117 to
5d003ed
Compare
- Added SnakeCase enum value to PropertyNameMappingStrategy with XML documentation - Implemented snake_case to PascalCase conversion for property matching - Updated MemberPathCandidateBuilder with new overload supporting naming strategies - Modified MembersMappingBuilderContext to use SnakeCase strategy when configured - Updated PublicAPI snapshot to reflect new enum value - Added test case for SnakeCase property mapping validation This allows to map properties between PascalCase and snake_case objects (e.g., FirstName -> first_name) by setting PropertyNameMappingStrategy = PropertyNameMappingStrategy.SnakeCase Co-authored-by: Lars <[email protected]>
5d003ed to
1ef6b21
Compare
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 SnakeCase Property Name Mapping Strategy
Description
This PR adds support for
SnakeCaseas a new property name mapping strategy in Mapperly, enabling automatic mapping between PascalCase properties in C# source objects and snake_case properties in target objects.Motivation
In modern C# development, it's common to work with external systems or code generators that produce DTOs with snake_case property names (e.g., from JSON APIs, database schemas, or code generation tools). Currently, mapping between C# PascalCase properties and snake_case properties requires manual
[MapProperty]attributes for each property, which is tedious and error-prone for large objects.This feature is particularly valuable when:
Changes Made
SnakeCaseenum value toPropertyNameMappingStrategywith XML documentationMemberPathCandidateBuilderMemberPathCandidateBuilderwith new overload supporting naming strategiesMembersMappingBuilderContextto use SnakeCase strategy when configuredUsage Example
This allows developers to map properties between PascalCase source objects and snake_case target objects (e.g.,
FirstName->first_name) by simply settingPropertyNameMappingStrategy = PropertyNameMappingStrategy.SnakeCase.Fixes # (issue - if applicable)
Checklist