question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NamingConvention for source and destination

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
TylerCarlson1commented, Feb 26, 2016

“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.

0reactions
lock[bot]commented, May 7, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Field Naming Convention
Sumo Logic recommends using the following naming convention for standard fields. ... For example, if you create your own FER for Source IP, ......
Read more >
File Naming Best Practices for Digital Asset Management
Explore our guide to digital asset management file naming conventions, and organize your DAM solution today.
Read more >
Naming Files, Paths, and Namespaces - Win32 apps
All file systems follow the same general naming conventions for an individual file: a base file name and an optional extension, separated by...
Read more >
Name conventions | Anapedia
Name conventions help model builders structure a model. It's important you follow ... The source and destination location. An abbreviation of the action...
Read more >
Conventions
Can overwrite the source and destination member naming conventions by passing a lambda through the parameter. SourceExtentionMethods can also be set here.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found