You should use a ValueResolver
(some more infos here) :
public class PersonNameResolver : ValueResolver<Person, string>
{
protected override string ResolveCore(Person value)
{
return (value == null ? string.Empty : value.FirstName + " " + value.LastName);
}
}
and your profile should be something like this:
public class ExampleProfile : Profile
{
protected override void Configure()
{
CreateMap<Person, PersonView>()
.ForMember(personView => personView.Name, person => person.ResolveUsing<PersonNameResolver>());
}
}
According to the author Formatters
are for global type conversions. You can read some of his replies here and here.
I would go for the first of your options:
CreateMap<Person, PersonView>()
.ForMember(personView => personView.Name, ex => ex.MapFrom(
person => person.FirstName + " " + person.LastName));
And apparently value formatters have been a mistake.