-
Notifications
You must be signed in to change notification settings - Fork 359
BuildAdapter().AdaptToType<T>() does not include all expected properties when source is using inheritance #776
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
Comments
@crates-barrels implementation and inheritance are different things. .Adapt working With runtime type of instance.
|
Thank you for the reply @DocSvartz and I'm sorry for using the wrong terminology. Anyway, I expected both methods to behave the same way, but I understand this is not the case because the underlying code is based on different things (runtime using Ultimately I would like to use
But when using that method, its behavior is different as described. Building further on the sample code, the following is similar to my current workaround where I would like to use
Is there another way to achieve this without having to create a method overload for every possible source type? |
Have you tried something like this configuration?
Update: |
Yes, These adapters detect the source type differently. Most likely you will need to register all implementations that may be at the source, as in example. TypeAdapterConfig<IMyInterface, MyDto>.NewConfig() |
@andrerav @stagep Of the obvious problems that may arise are:
What do you think about this? |
While rewriting some code to use the async implementation of adapt using package Mapster.Async v2.0.1, I stubled upon an issue where not all expected source properties were copied to the result class.
However, the code was working as expected when I was using
.Adapt<T>()
.I've tracked it down to the source class being inherited from a base class and using a method where the parameter is of this base class type.
The following code can be used (e.g. in a console application) to reproduce the issue and show the difference in behavior between
.Adapt<T>()
andAdaptToType<T>()
:This code is using
AdaptToType<T>()
to not complicate things by using an additional package (Mapster.Async), but theAdaptToTypeAsync<T>()
method has the same behavior.When running the application, the output is as follows:
Results 1, 2 and 3 are as expected, but the last result only includes the
IMyInterface
property (InterfaceProperty
) and not the additionalMyImplementation
properties (FirstImplementationProperty
andSecondImplementationProperty
) marked in bold.Versions used in code sample:
The text was updated successfully, but these errors were encountered: