Skip to content
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

Access to already resolved destination properties when using resolve #175

Closed
nvdnkpr opened this issue Jul 31, 2020 · 1 comment
Closed
Labels
investigate question Further information is requested

Comments

@nvdnkpr
Copy link

nvdnkpr commented Jul 31, 2020

Hello @nartc,
I'm curious about the purpose of the destination object in the resolver. Is there any way for e.g. User (title, first, last) to UserVm(first, last, fullName, fullTitle) where the mappings are:

  • d.first -> s.first
  • d.last -> s.last
  • d.fullName -> s.first + ' ' + s.last
  • d.fullTitle -> s.title + ' ' + d.fullName (option 1)

I know there is always (option 2) where d.fullTitle can be defined as s.title + ' ' + s.first + ' ' + s.last.

I'm asking this to know if there is any possiblity to

  • avoid defining the fullname part twice when using option 2
  • for more complex examples to re-use an already evaluated mapping in the same destination object
@nartc nartc added question Further information is requested investigate labels Jul 31, 2020
@nartc
Copy link
Owner

nartc commented Aug 1, 2020

The order of the mapping configurations is reversed (due to the reason we talked about on Discord). So if you want to access d.fullName in d.fullTitle, do the following:

createMap(Source, Destination)
   .forMember(d => d.fullTitle, ...)
   .forMember(d => d.fullName, ...)

d.fullName is configured last so it will be mapped first. If you were to use any Member Map that has access to destination object, you would have access to d.fullName.

Another approach is to use afterMap like following:

createMap(Source, Destination)
   .forMember(d => d.fullTitle, ignore()) // we ignore it
   .forMember(d => d.fullName, ...)
   .afterMap((source, destination) => {
      destination.fullTitle = ...; // map it here. At this moment, destination is ensured to have all manual-configured properties mapped.
   })

I'm going to close this issue until there's change in the future. If there is, I'll open a new issue to keep track. Thanks for the issue.

@nartc nartc closed this as completed Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants