Automapper unflatten with a prefix

I have some DTOs that map to Domain objects, thanks to legend-based auto-tuning, that is, Address fields are smoothed out in the DTO.

This works fine for Domain → DTO conversion, but in another way I have to "unflatten" Address manually.

I wonder if there is a “prefix” option for the display configuration, so I could do something like

Mapper.CreateMap<PersonDTO, Address>().WithPrefix("Address");
...
Mapper.CreateMap<PersonDTO, Person>()
.ForMember(d => d.Address, opt => opt.MapFrom(src => Mapper.Map<Address>(src) ))

Otherwise, I need to manually map each address field, which becomes a problem for more complex objects.

my domain objects and DTO

class Person
{
    public string FirstName {get;set;}
    public string LastName {get;set;}
    public Address Address {get;set;}
}

class Address
{
    public string Street {get;set;}
    public string PostCode {get;set;}
}

and the following DTO:

class PersonDTO
{
    public string FirstName {get;set;}
    public string LastName {get;set;}
    public string AddressStreet {get;set;}
    public string AddressPostCode {get;set;}
}

change

I know the global configuration of "recognized prefixes." I would prefer to set a mandatory prefix (rather than "one of the recognized") for a particular Card.

+3
1
0

All Articles