Skip to content

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

Closed

Description

@rafalka

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions