Reputation: 53
I have the following class and interface definitions, and would like to use EmitMapper instead of AutoMapper to map from class to interface. The current code works, but I'd like to use EmitMapper, yet have not figured out how to use it.
public interface ITreeViewDTO
{
int Id { get; set; }
string Name { get; set; }
int? Parent_Id { get; set; }
string ExtraData { get; set; }
IEnumerable<ITreeViewDTO> SubNode { get; set; }
}
public class Navigation
{
public int Id { get; set; }
public string Name{ get; set; }
public int? Parent_Id { get; set; }
public virtual IList<Navigation> SubNavigations { get; set; }
}
This is the current AutoMapper configuration for the desired mapping:
Mapper.CreateMap<Navigation, ITreeViewDTO>()
.ForMember(dest => dest.SubNode,
opt => opt.MapFrom<IEnumerable<Navigation>>(src => src.SubNavigations));
var iTreeView = Mapper.Map<Navigation, ITreeViewDTO>(root);
What would be the equivalent EmitMapper code for the above sample?
Upvotes: 2
Views: 1033