Skip to content

Instantly share code, notes, and snippets.

@schotime
Created June 15, 2010 06:57
Show Gist options
  • Save schotime/438783 to your computer and use it in GitHub Desktop.
Save schotime/438783 to your computer and use it in GitHub Desktop.
//Take this
public ActionResult Logins()
{
var mapped = _repository
.Query(new GetLoginHistoryAndUser())
.AutoMap<LoginHistory, LoginHistoryDisplay>()
.ToList();
return View(new LoginHistoryViewModel { LoginHistory = mapped });
}
//with this
public static IEnumerable<Y> AutoMap<T, Y>(this IEnumerable<T> list)
{
return list.Select(x => Mapper.Map<T, Y>(x));
}
//Why can't i write this (omitting the first type in the AutoMap method)
public ActionResult Logins()
{
var mapped = _repository
.Query(new GetLoginHistoryAndUser())
.AutoMap<LoginHistoryDisplay>()
.ToList();
return View(new LoginHistoryViewModel { LoginHistory = mapped });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment