-
Notifications
You must be signed in to change notification settings - Fork 397
Open
Labels
Description
Hello. I am trying to map an object with getter-only properties using a custom Map functon. This seems to be broken in v10.0.6, while it was fine in v7.4.0. See the following sample:
var typeAdapterConfig = new Mapster.TypeAdapterConfig();
typeAdapterConfig.Scan(typeof(Program).Assembly);
typeAdapterConfig.Compile();
var mapper = new MapsterMapper.Mapper(typeAdapterConfig);
var dto = new Dto { Data = new("new") };
Console.WriteLine(mapper.Map(dto, new Entity { Data = new("old") }).Data?.Value); // outputs "old" with v10.0.6, outputs "new" with v7.4.0
Console.WriteLine(mapper.Map(dto, new Entity()).Data?.Value); // outputs "new" with both v10.0.6 and v7.4.0
Console.WriteLine(mapper.Map<Entity>(dto).Data?.Value); // outputs "new" with both v10.0.6 and v7.4.0
class Dto { public Data? Data { get; set; } }
class Entity { public Data? Data { get; set; } }
class Data(string value) { public string Value => value; }
class Mappings : Mapster.IRegister
{
public void Register(Mapster.TypeAdapterConfig config)
{
config.NewConfig<Dto, Entity>()
.Map(x => x.Data, x => x.Data == null ? null : new Data(x.Data.Value));
}
}Specifically this case seems to be broken:
var dto = new Dto { Data = new("new") };
var entity = mapper.Map(dto, new Entity { Data = new("old") });I would expect the result entity's Data property to be mapped correctly from the source dto, as specified in the mapping function:
config.NewConfig<Dto, Entity>().Map(x => x.Data, x => x.Data == null ? null : new Data(x.Data.Value));
As noted, Mapster v7.4.0 seems to be find, but v10.0.* seems to be broken.
Or maybe I am missing something here, please advise, thank you.
Reactions are currently unavailable