-
Notifications
You must be signed in to change notification settings - Fork 334
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
Mapping with constructor and default values for ignored properties? #707
Comments
Hello @DumboJetEngine |
@DumboJetEngine |
@DocSvartz
I didn't care much about the preexisting |
@DumboJetEngine Thanks. The example served as a good basis for finding the source of the problem. :) If this is what you expected. Then most likely in the next releases. It will be added.
|
I try to map from class A to class B, where B is missing a property of A.
Usually, to do this you have to use
.Ignore(e => e.Property)
but I use a non-default constructor for initialization of the destination class (because I need to validate the incoming data within the constructor) and this fails.Apparently, Mapster removes the ignored parameter from the constructor invocation parameters instead of using the default parameter value. And this inevitably fails.
Here is some sample code:
My humble opinion is that this code should work and invoke the constructor using the default value for
Id
, which isdefault(int)
, which is0
. Omitting it during the invocation, which is what currently appears to happen, makes little sense to me.I would also fancy an
.Ignore()
overload method that allows providing the value for the property, like this one:...but perhaps this is too much to ask.
P.S. :
I know I could use
.MapWith(a => new B(0, a.Text))
to manually fix the issue, but I try to keep the mapping as automated as possible, because I need to do this configuration for many types that contain a lot of constructor parameters and this would be messy. So, this is not an option for my case.The text was updated successfully, but these errors were encountered: