Replies: 2 comments 5 replies
-
Mapping the properties like this almost works, but 1. is very tedious and 2. doesn't work because I get RMG020: "The member Item1 on mapping source etc.)" [Mapper]
public static partial class Map
{
[MapProperty(new[] { nameof(input.A), nameof(input.A.PropA) }, new[] { nameof(RecordB.PropA) })]
[MapProperty(new[] { nameof(input.A), nameof(input.A.PropB) }, new[] { nameof(RecordB.PropB) })]
public static partial RecordB ToRecordB(this (RecordA A, long ParamC) input);
} result: public static partial class Map
{
public static partial global::RecordB ToRecordB(this (global::RecordA A, long ParamC) input)
{
var target = new global::RecordB(input.ParamC)
{
PropA = input.A.PropA,
PropB = input.A.PropB
};
return target;
}
} |
Beta Was this translation helpful? Give feedback.
-
Unfortunately mapperly does not support multiple mapping parameters 😞, although this is likely to change in the future. See #103. Your manual work around is really clever, I'm not sure why mapperly can access both your named field aliases and the default tuple field names, I wonder if this is due to a roslyn quirk. Mapperly records which members have been mapped and which haven't. In your case mapperly sees your source as having 4 members: I'll see if I can prevent RMG020 when the field has been mapped. |
Beta Was this translation helpful? Give feedback.
-
I love the idea of mapperly, it hands down has the best approach to mapping and mostly does what I need.
However, I've shit a snag:
Is there any way I can get this working?
Mapperly doesn't seem to like named tuples as it complains about "Item1" and "Item2" amongst other things.
I know if the properties weren't init props I could write a void mapping method, but it feels wrong to change my classes to support mapperly.
If anyone wonders about the use case it's an aspnetcore application where part of the parameters come from the url, while the rest are provided in the body, so passing them all as one model to the domain requires this mapping.
Beta Was this translation helpful? Give feedback.
All reactions