-
-
Notifications
You must be signed in to change notification settings - Fork 203
feat: Add SnakeCase strategy to PropertyNameMappingStrategy #2011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
latonz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution. I added my feedback. IMO we should also support auto flattening (see docs) and UpperSnakeCase.
|
Please also update the documentation. |
|
Hi @latonz, |
latonz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
test/Riok.Mapperly.Tests/Descriptors/MemberPathCandidateBuilderTest.cs
Outdated
Show resolved
Hide resolved
|
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 <lars@riok.ch>
5d003ed to
1ef6b21
Compare
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