Misleading exception message for ctor argument names
还没有人认领这个 Issue。
评估
调研方向
从报告中的 constructor-mapping 示例里的 config.Compile() 调用开始,跟踪构造函数参数名称的匹配方式,以及 no-default-constructor 异常的生成方式。比较参数命名为 number 而不是 id 时的行为,然后使结果和异常措辞反映受支持的 constructor-mapping 选项,并验证现有的 mapping 场景。
由索引模型根据 Issue 内容生成。
描述
There's an exception produced when mapping to a class with a ctor:
public class Destination
{
public Destination(int number)
{
Id = number;
}
public int Id { get; }
}
public class Source
{
public int Number { get; set; }
}
[Fact]
public void Should_Map()
{
var config = new TypeAdapterConfig();
config.ForType<Source, Destination>()
.Map(dest => dest.Id, source => source.Number);
config.Compile(); // throws an exception
}
The following exception is produced:
System.InvalidOperationException : No default constructor for type 'Destination', please use 'ConstructUsing' or 'MapWith'.
The exception message seems misleading as (I may have missed it in documentation) mapster seems to depend on argument names.
Renaming Destination ctor argument from number to id is enough for the test to succeed. That is, changing to the following:
public class Destination
{
public Destination(int id)
{
Id = id;
}
public int Id { get; }
}
Suggestions:
- maybe this name-dependency could be reduced?
- it would be great if the exception message could mention that there's an option of renaming ctor arguments to match the properties
- 主要语言
- 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
-
dev/release: verify-release-candidate.sh runs 0 Java tests with Debian's Maven可能已有人在做 @kou 今天认领。 未关闭Type: bug
难度 2/5 1-3 小时 新手友好度 72/100
apache/arrow-adbc#4947 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/fluentui-blazor#5535 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 74/100
AvaloniaUI/Avalonia#22582 ·
维护者通常 2 天内回复
-
:watch: Not Triaged CAC
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/AspNetCore.Docs#38001 ·
维护者通常 1 天内回复
-
HTTP logging truncates catch-all route parameters in the formatted request path可能已有人在做 @johnkaram02 今天认领。 未关闭area-telemetry untriaged
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/extensions#7883 ·
维护者通常 1 天内回复