Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aarondandy/4296390bee8bb82771040d43925e1cc9 to your computer and use it in GitHub Desktop.
Save aarondandy/4296390bee8bb82771040d43925e1cc9 to your computer and use it in GitHub Desktop.
automapper things
public class FooCopier
{
public static FooCopier Default { get; } = new FooCopier();
public static FooCopier WithoutBar { get; } = new FooCopier(skipBar: true);
private readonly IMapper mapper;
public FooCopier(bool skipBar = false)
{
var config = new MapperConfiguration(m =>
{
var expression = m.CreateMap<Foo, Foo>();
if (skipBar)
{
expression = expression.ForMember(x => x.Bar, opt => opt.Ignore());
}
});
this.mapper = config.CreateMapper();
}
public void Apply(Foo source, Foo destination)
{
mapper.Map(source, destination);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment