MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.23k stars 325 forks source link

ShallowCopyForSameType(true) not working with Mapster.Tool #668

Open ichalyshev opened 7 months ago

ichalyshev commented 7 months ago

I have type hierarchy

public class ProvinceInfo
{
    public string Code { get; set; }
    public string Title { get; set; }
}

class Address
{
    public ProvinceInfo Province { get; set; } 
}

class AddressState
{
    public ProvinceInfo Province { get; set; } 
}

and mapster config

...
config
    .NewConfig<ProvinceInfo, ProvinceInfo>()
    .ShallowCopyForSameType(true);

config
    .NewConfig<AddressState, Address>()
    .ShallowCopyForSameType(true)
...

when i generate mappers with Mapster.Tool i consistantly receive deep copy:

public AddressState MapTo(Address p1)
...
Province = new ProvinceInfo()
{
    Code = p1.Province.Code,
    Title = p1.Province.Title
},
...

i neen copy by reference here, but can't achive it.

By the way, please suggest mapster learning materials. Official docs seems useless.

ichalyshev commented 7 months ago

my fault