NamingConvention for source and destination
See original GitHub issueI am currently using AutoMapper 3.3.1, so bear with me if this was changed in a later version.
When I saw, that there were both Source and Destination naming conventions, I thought that they could be used to level the naming differences between objects, such that a Pascal-cased property could be mapped to/from lower-cased. But this showed to be untrue.
The way it works is that it uses Destination naming convention object’s SplittingExpression
to split the destination property name into parts, and then it uses Source naming convention’s SeparatorCharacter
(which, funny enough, is a string 😃 ) to merge the parts. Destination’s SeparatorCharacter
and Source’s SplittingExpression
are blutantly ignored.
This made it untrivial to map e.g. a source property PersonClass_Id
into PersonClassId
, for the source property name is never modified. What I did as a workaround is I split on the “Id” ending, but this is a hack.
What I would expect for this to work is that before actual string comparison, both property names are split and merged in accordance with their naming conventions.
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
“sometimes” meaning not all the time. AutoMapper assumes you keep the naming convention consistent and “PascalCase_Id” is a mix of Pascal and underscore naming conventions so there’s no way AutoMapper can map it one way or the other. This is also used for splitting names up to do flattening. If you do this the way you have now, then only underscores will be split up for flattening. Pascal can never be used.
So in order to make this scenario work AutoMapper would need a MemberNamingConvention list for source and destination. And you would add both Pascal and Underscore naming conventions. Then when you split and rejoin all the text you would have to do every possibly combination of every NamingConvention you have in your list.
This should be able to be supported in AutoMapper if you add a list.
As far as the last line in your original post. It splits down the source’s value using it’s own naming convention and it re-assembles it using the destinations’s naming convention. So it converts PascalCaseId to pascal_case_id when one is PascalName and the other is Underscore.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.