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

Unable to map classes with generics

Aperta
#724 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
tooling

Direzione di ricerca

Non sono indicati file, test o punti di ingresso. Inizia riproducendo gli errori in fase di compilazione e di runtime descritti qui con Audit, le sottoclassi di LogData, i DTO e le configurazioni Include e IgnoreNonMapped descritte qui; il lavoro è completato quando il comportamento previsto e una correzione mirata sono stabiliti per entrambi i casi di mapping generico.

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

Descrizione

configuration problem

I would want to map a class structure for logs. The main class is a generic class Audit<T> where T is class LogData or a subclass it.
DTO would have a simple structure with AuditDTO and property of type LogDataDTO, that object has all the possible subclass properties united in it.

  • My initial issues occurred at compile time as CompileException .
    If my configuration has
    config.NewConfig<LogData, LogDataDTO>() <-- with all base class properties mapped plus
    .IgnoreNonMapped(true)
    .Include<LogDataSubclass, LogDataDTO>() <-- for all subclass of LogData

and
config.NewConfig<LogDataSubclass, LogDataDTO>() <-- with all the specific subclass properties mapped plus
.IgnoreNonMapped(true)

then it would complain about LogDataDTO not having a corresponding source member mapped or ignored: SOME properties of LogDataSubclasses' - but weird enough not all of them. If I added to the LogData baseclass config explicitly the .Ignore(dest => dest.ProblematicSubclassProp) then that would solve the issue.

  • Second issue occurred afterward at runtime. The AuditDTO had the same exception that its properties, other than the LogData, are not mapped or ignored. Adding an explicit config for mapping seems trickier as it does not seem to work with invariance:
    if there's config.NewConfig<Audit<LogData>(), AuditDTO>(), or any other type of <Audit<LogDataSubclass>, AuditDTO> then the source type causing the error is referred to as <IAudit<ILogData>>. (Conventional interfaces)

I have the impression that i heavily overcomplicate the config and not using (misusing) some methods here... IgnoreNonMapped is definetely not working as expected and makes this whole declarartion redundant.

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.