I have the following model:
public class Tag
{
public int Id { get; set; }
public string Name { get; set; }
}
I want to be able to
This is because you are trying to map to the actual destination type rather than a property of the destination type. You can achieve what you want with:
Mapper.CreateMap<Tag, string>().ConvertUsing(source => source.Name ?? string.Empty);
although it would be a lot simpler just to override ToString on the Tag class.
ForMember means you are providing mapping for a member where you want a mapping between type. Instead, use this :
Mapper.CreateMap<Tag, String>().ConvertUsing<TagToStringConverter>();
And Converter is
public class TagToStringConverter : ITypeConverter<Tag, String>
{
public string Convert(ResolutionContext context)
{
return (context.SourceValue as Tag).Name ?? string.Empty;
}
}