Automapper: Mapping a property value of an object to a string

Using Automapper, how do you handle the mapping of a property value on an object to an instance of a string. Basically I have a list of Role objects and I want to use Automapper to map the content of each "name" property to a corresponding list of string (so I just end up with a list of strings). I'm sure it has an obvious answer, but I can't find the mapping that I need to add to "CreateMap" to get it to work.

An example of the relevant code is shown below:

public class Role
{
   public Guid Id{get;set;}
   public string Name{get;set;}
   ...
   ...
}

// What goes in here?
Mapper.CreateMap<Role, string>().ForMember(....);

var allRoles = Mapper.Map<IList<Role>, IList<string>>(roles);
14
задан Paul Hadfield 14 December 2010 в 13:58
поделиться