Extension Method for Domain => ViewModel

Mar 16, 2011 at 9:28 PM

Anyone who doesn't want to use their domain model to push to the view will need to map their domain to the view model. Here's an extension to help with that.

	public static class PagedListExtensions
	{
		public static PagedList<TResult> ToViewModelMappedPagedList<T, TResult>( this PagedList<T> list, Func<T, TResult> selector )
		{
			return new PagedList<TResult>( list.Select( selector ), list.CurrentPageIndex, list.PageSize, list.TotalItemCount );
		}
	}