Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Unable to map classes with generics

Abierto
#724 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
tooling

Línea de trabajo

No se especifican archivos, pruebas ni puntos de entrada. Empieza reproduciendo los fallos en tiempo de compilación y de ejecución descritos aquí con Audit, las subclases de LogData, los DTOs y las configuraciones Include e IgnoreNonMapped; se considera terminado cuando el comportamiento esperado y una corrección específica estén establecidos para ambos casos de mapping genérico.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
5.2k
Forks
411
Merge medio
1 d 8 h
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MapsterMapper/Mapster

Todos los issues de MapsterMapper/Mapster

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.