public class Source { public string Name { get; set; } public int Age { get; set; } } public class Destination { public string FullName { get; set; } public int Age { get; set; } }
var config = new MapperConfiguration(cfg => cfg.CreateMap
public class User { public int UserId { get; set; } public string Name { get; set; } public Address Address { get; set; } } public class Address { public string Street { get; set; } public string City { get; set; } public string ZipCode { get; set; } }
var config = new MapperConfiguration(cfg => { cfg.CreateMapIn both examples, we are configuring the mapping using the MapperConfiguration class and then creating a mapper using the CreateMapper method. The mapper can then be used to map data between objects.() .ForMember(dest => dest.City, opt => opt.MapFrom(src => src.Address.City)); }); IMapper mapper = config.CreateMapper(); var user = new User { UserId = 1, Name = "John", Address = new Address { Street = "123 Main St", City = "New York", ZipCode = "10001" } }; var userDto = mapper.Map (user);