[AdaptTo("[name]Dto"), GenerateMapper]
当我用一切正常来装饰我的域类时,但是当我使用时:
public class MappingRegister : ICodeGenerationRegister
{
public void Register(CodeGenerationConfig config)
{
config.AdaptTo("[name]Read")
.ForType<Command>();
config.GenerateMapper("[name]Mapper")
.ForType<Command>();
}
}
它生成与属性相同的 dto 类,但映射器类为空:
public static partial class CommandMapper
{
}
我想念什么?
更新
所以我遇到的问题不在于属性与 ICodeGenerationRegister 实现,而是我必须运行构建两次的事实。它第一次生成一个空的映射器类,在第二次构建时,我得到了生成的扩展方法。
这是我的项目配置
...
<Target Name="Mapster" AfterTargets="AfterBuild">
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet tool restore" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster model -a "$(TargetDir)$(ProjectName).dll" -n Commands.Dtos -o Dtos" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster extension -a "$(TargetDir)$(ProjectName).dll" -n Commands.Dtos -o Dtos" />
<Exec WorkingDirectory="$(ProjectDir)" Command="dotnet mapster mapper -a "$(TargetDir)$(ProjectName).dll" -n Commands.Dtos -o Dtos" />
</Target>
...
Mapster 工具版本 8.0.1