Allow to access all object properties via MapProperty.Use function instead of just one field
Is your feature request related to a problem? Please describe.
For now, MapProperty.Use allows just one field to have custom mapping, i.e.:
[Mapper]
public partial class CarMapper
{
[MapProperty(nameof(Car.Price), nameof(CarDto.Price), Use = nameof(MapPrice))]
public partial CarDto MapCar(Car source);
[UserMapping(Default = false)]
private string MapPrice**(decimal price)**
=> (price / 100).ToString("C");
}
My use-case requires to be able to access other model properties to use them in mapping logic. Describe the solution you'd like
[Mapper]
public partial class CarMapper
{
[MapProperty(nameof(Car.Price), nameof(CarDto.Price), Use = nameof(MapPrice))]
public partial CarDto MapCar(Car source);
[UserMapping(Default = false)]
private string MapPrice**(Car car)**
=> (car.Price + car.Markup / 100).ToString("C");
}
Describe alternatives you've considered MapPropertyFromSource allows this behaviour, but it can't work if there source and destination have different property names.
Additional context Automapper allows doing it like this, and this thing IMO should be here too as it would help to migrate from Automapper. Thank you in advance! 🙃
Just use before-/aftermap and an ignore?
@latonz Thank you for suggestion, it worked for me! Although it still would be nice to have something like I suggested 😄