Unable to map classes with generics
还没有人认领这个 Issue。
评估
调研方向
未指定文件、测试或入口点。首先使用此处描述的 Audit、LogData 子类、DTO、Include 和 IgnoreNonMapped 配置,复现所报告的编译时和运行时失败;对于两个泛型 mapping 场景,都确立预期行为和针对性修复后,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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
AuditDTOhad 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'sconfig.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.
- 主要语言
- C#
- 星标
- 5.2k
- 派生
- 411
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MapsterMapper/Mapster 的其他 Issue
-
.NET Matrix未关闭
难度 2/5 1-3 小时 新手友好度 72/100
MapsterMapper/Mapster#1003 ·
-
难度 3/5 1-2 天 新手友好度 58/100
MapsterMapper/Mapster#1024 · 1 条评论 ·
-
[Mapster Tool] Add support for global:: to disambiguate type names in generated mappers可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭improvement
难度 3/5 1-2 天 新手友好度 65/100
MapsterMapper/Mapster#1020 · 5 条评论 ·
-
Mapster.Tool - PropertySettingBuilder.Map(member, mapFunc, targetPropertyName) method is not working as expected!可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
MapsterMapper/Mapster#1017 · 6 条评论 ·
-
难度 3/5 1-2 天 新手友好度 57/100
MapsterMapper/Mapster#1007 · 5 条评论 ·
查看 MapsterMapper/Mapster 的全部 Issue
相似的 Issue
-
area: backend enhancement payments
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
-
S: Untriaged
难度 2/5 1-3 小时 新手友好度 67/100
Trauma-Station/Trauma-Station#5159 ·
维护者通常 1 天内回复
-
Crashes immediately when trying to join CnCNet lobby using macOS + CrossOver可能已有人在做 @QyInvoLing 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 67/100
CnCNet/xna-cncnet-client#1150 ·
维护者通常 1 天内回复