Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Add - Inherits Lazy

Open DocSvartz opened this issue 5 months ago • 0 comments

add Setting: .InheritsLazy<,>()

Lazy loads settings for inherited types during the first call to Adapt<>

Example:

 TypeAdapterConfig<DerivedPoco, DerivedDto>.NewConfig()
                .InheritsLazy<SimplePoco, SimpleDto>()
                .Compile();

            TypeAdapterConfig<SimplePoco, SimpleDto>.NewConfig()
                .InheritsLazy<RootPoco, RootDto>()
                .Ignore(dest => dest.Name)
                .Compile();

            TypeAdapterConfig<RootPoco, RootDto>.NewConfig()
                .Map(dest => dest.NumberDto, src => 42)
                .Compile();

            dto = TypeAdapter.Adapt<DerivedDto>(source);

            dto.Id.ShouldBe(source.Id);
            dto.Name.ShouldBeNull();  // InheritsLazy Ignore is work
            dto.NumberDto.ShouldBe(42); // InheritsLazy is work

DocSvartz avatar Jul 14 '25 12:07 DocSvartz