-
Hi. public record Model(uint Prop1, string Prop2, string? Prop3 = null, string? Prop4 = null, string? Prop5 = null);
public record Dto(uint DtoProp1, string DtoProp2, Dto.Metadata DtoData)
{
public record Metadata(string? Prop1 = null, string? Prop2 = null, string? Prop3 = null);
} Necessary mapping:
I tried the following option but I get an error [Mapper]
public static partial class Mapper
{
[
MapProperty(nameof(Model.Prop1), nameof(Dto.DtoProp1)),
MapProperty(nameof(Model.Prop2), nameof(Dto.DtoProp2)),
MapProperty(nameof(Model.Prop3), nameof(@Dto.DtoData.Prop1)),
MapProperty(nameof(Model.Prop4), nameof(@Dto.DtoData.Prop2)),
MapProperty(nameof(Model.Prop5), nameof(@Dto.DtoData.Prop3))
]
public static partial Dto MapToDto(this Model model);
} Produced mapping code: // <auto-generated />
#nullable enable
namespace Namespace
{
public static partial class Mapper
{
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.1.0.0")]
public static partial global::Namespace.Dto MapToDto(this global::Namespace.Model model)
{
var target = new global::Namespace.Dto()
{
DtoProp1 = model.Prop1,
DtoProp2 = model.Prop2,
};
return target;
}
}
} The documentation does not provide a detailed description for such mapping, it only mentions the use of the How can I configure the mapper to get the desired result? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The compilation of your code should result in |
Beta Was this translation helpful? Give feedback.
The compilation of your code should result in
RMG016: Init only member cannot handle target paths
. Mapperly does not support paths for init only members. See #643