diff --git a/docs/Define-Maps.rst b/docs/Define-Maps.rst index 500d01d..1d25a44 100644 --- a/docs/Define-Maps.rst +++ b/docs/Define-Maps.rst @@ -7,7 +7,10 @@ There are three interfaces that enable the definition of mappings making; 2. IMapFrom 3. ICustomMap -The first two enable the definition of simple mappings i.e. If you have a database entity and domain entity +IMapTo & IMapFrom +------------------ + +The IMapTo and IMapFrom interfaces enable the definition of simple mappings i.e. If you have a database entity and domain entity that may have the same properies eg. A database entity that has two properties @@ -43,4 +46,39 @@ interfaces to define the mappings public string Description {get;set;} } +Once the interface has been implemented and the designated class name supplied there is nothing else you need to do to implement the mapping. +The automapper libraries take care of all the mapping for you. + +ICustomMap +---------- + +The ICustomMap interface is required if your objects require more complex mapping logic. The interface requires +the implementation of a mapping method +:: + + public interface ICustomMap + { + void CustomMap(IMapperConfigurationExpression configuration); + } + +It is in the CustomMap method that you can use all the power and functionality of Automapper to implement your required mapping logic + +:: + + public class ComplexDomainObject :ICustomMap + { + public string Firstname { get; set; } + public string LastName { get; set; } + public string Summary { get; set; } + public string Title { get; set; } + public int Age { get; set; } + public void CustomMap(IMapperConfigurationExpression configuration) + { + configuration.CreateMap() + .ForMember(dest => dest.Name, opt => opt.MapFrom(src => string.Concat( src.Firstname, " ", src.LastName ))) + .ForMember(dest => dest.Description, opt => opt.MapFrom(src => string.Concat( src.Title , " ", src.Summary))) + .ForMember(dest => dest.Age, opt => opt.MapFrom(src => src.Age)); + + } + } \ No newline at end of file