How can I map a List like this? How would my CreateMap look? The class for PagedList looks like this:
public interface IPagedList
{
int TotalCount
{
get;
set;
}
int PageIndex
{
get;
set;
}
int PageSize
{
get;
set;
}
bool IsPreviousPage
{
get;
}
bool IsNextPage
{
get;
}
}
public class PagedList<T> : List<T>, IPagedList
{
public PagedList(IQueryable<T> source, int index, int pageSize)
{
this.TotalCount = source.Count();
this.PageSize = pageSize;
this.PageIndex = index;
this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
}
public PagedList(List<T> source, int index, int pageSize)
{
this.TotalCount = source.Count();
this.PageSize = pageSize;
this.PageIndex = index;
this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
}
public PagedList()
{
}
public int TotalCount
{
get;
set;
}
public int PageIndex
{
get;
set;
}
public int PageSize
{
get;
set;
}
public bool IsPreviousPage
{
get
{
return (PageIndex > 0);
}
}
public bool IsNextPage
{
get
{
return (PageIndex * PageSize) <= TotalCount;
}
}
}
My mapping code:
Mapper.CreateMap<User, UserModel>();
var model = Mapper.Map<PagedList<User>, PagedList<UserModel>>(users); // Not quite sure about this.
When I do the above, Only the list gets mapped, the other properties such as TotalCount, PageSize, are not mapped.