Skip to main content

Additional mapping parameters

A mapping method declaration can have additional parameters. Each additional parameter is considered the same as a source member and matched by its case-insensitive name. An additional mapping parameter has lower priority than a MapProperty mapping, but higher than a by-name matched regular member mapping.

[Mapper]
public partial class CarMapper
{
public partial CarDto Map(Car source, string name);
}

public class Car
{
public string Brand { get; set; } = string.Empty;
public string Model { get; set; } = string.Empty;
}

public class CarDto
{
public string Brand { get; set; } = string.Empty;
public string Model { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
}
info

Mappings with additional parameters do have some limitions:

  • The additional parameters are not passed to nested mappings.
  • A mapping with additional mapping parameters cannot be the default mapping (it is not used by Mapperly when encountering a nested mapping for the given types), see also default mapping methods.
  • Generic and runtime target type mappings do not support additional type parameters.