Mapperly 有没有什么办法可以从多个来源返回一个新对象?像这样:[Mapper]public partial class Mapper { public partial VehicleRecord From(VehicleContract Vehicle,
有没有办法使用 Mapperly 从多个来源返回一个新对象?像这样:
[Mapper]
public partial class Mapper {
public partial VehicleRecord From(VehicleContract Vehicle, string userId);
}
原因是我需要创建一个 VehicleRecord
要存储在数据库中:
public class VehicleRecord {
[DynamoDBHashKey] public required string UserId { get; init; }
[DynamoDBProperty] public required string ModelName { get; init; }
/*
... more properties ...
*/
}
来自两个来源:
string userId = GetAuthenticatedUserId()
VehicleContract
:
[HttpPost]
public async Task<ActionResult> PostVehicle([FromBody] VehicleContract vehicle) {
string userId = GetAuthenticatedUserId();
VehicleRecord dbRecord = mapper.From(vehicle);
// ... store in DB ...
}
[DataContract]
public class VehicleContract {
[DataMember] public required string ModelName { get; init; }
/*
... more properties ...
*/
}
我尝试了 MapProperty
所有我能想到的方法,但无法让它与两个源一起工作。我还仔细阅读了文档以找到一种方法来做到这一点,但一无所获。有没有办法用 Mapperly 做到这一点?