Skip to content

Commit

Permalink
Adding more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
garywoodfine committed Feb 20, 2018
1 parent b265645 commit 37b2abe
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion docs/Define-Maps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ComplexDomainObject, SimpleEntity>()
.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));
}
}

0 comments on commit 37b2abe

Please sign in to comment.