Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Mapping an object with getter only properties seems to be broken in v10.0.6 (works as expected in 7.4.0)

Aperta
#900 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
csharp
Ambito
backend

Direzione di ricerca

Inizia eseguendo la riproduzione C# fornita con Mapster v10.0.6 e confronta il mapping personalizzato Dto-to-Entity con v7.4.0. Traccia il comportamento del mapping su una Entity esistente quando Data ha un Value con il solo getter e conferma che è completato quando l’Entity esistente riceve il nuovo valore di Data, mentre gli altri casi mostrati continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

configuration problem

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.

Lingua principale
C#
Stelle
5.2k
Fork
411
Merge medio
1g 8h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MapsterMapper/Mapster

Tutte le issue di MapsterMapper/Mapster

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.