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

Execution order of BeforeMapping() and AfterMapping() is incorrect #602

Closed
rafalka opened this issue Jul 4, 2023 · 0 comments · Fixed by #603
Closed

Execution order of BeforeMapping() and AfterMapping() is incorrect #602

rafalka opened this issue Jul 4, 2023 · 0 comments · Fixed by #603

Comments

@rafalka
Copy link

rafalka commented Jul 4, 2023

When BeforeMapping()/AfterMapping() are defined for base and derived class mapping then they are executed in incorrect order: base class BeforeMapping()/AfterMapping() is executed after such method from derived class

Sample code (based on After_Mapping() UT):

Types def

        public class SimplePocoBase
        {
            public string Name { get; set; }
        }

        public class SimplePoco : SimplePocoBase
        {
            public Guid Id { get; set; }
        }

        public class SimpleDto
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
        }

Mapping def

            TypeAdapterConfig<SimplePocoBase, SimpleDto>.NewConfig()
                .AfterMapping((src, dest) => dest.Name = src.Name + "BASE");
            TypeAdapterConfig<SimplePoco, SimpleDto>.NewConfig()
                .AfterMapping((src, dest) => dest.Name = src.Name + "SRC");

            var poco = new SimplePoco
            {
                Id = Guid.NewGuid(),
                Name = "test",
            };
            var result = TypeAdapter.Adapt<SimpleDto>(poco);

Expected result: result.Name should be testSRC
Actual result: result.Name is testBASE

Code for testing BeforeMapping() is similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant