I have a domain model that contains member variables for two languages, something like this:
public class Resource
{
public string SwedishName;
public string EnglishName;
}
For presentation I have a simplified model, that is delivered to a json serializer:
[JsonObject]
public class JsonResource
{
[JsonProperty]
public string Name;
}
These are mapped with automapper like so:
Mapper.CreateMap<Resource, JsonResource>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.SwedishName));
My question is, if this is possible to do in a more conditional way, depending on which language is asked for? My initial thought, was something along these lines:
string lang = "en";
json = Mapper.Map<Resource, JsonResource>(resource, lang)
Though, it does not seem possible to have several mappings for the same types?
Currently Im leaning towards, just defining another identical presentation model for the other language:
if (lang == "en")
json = Mapper.Map<Resource, EnglishJsonResource>(resource)
else
json = Mapper.Map<Resource, JsonResource>(resource)
Is this a feasible solution, or is there a better way?