Created
August 7, 2019 19:40
-
-
Save aarondandy/4296390bee8bb82771040d43925e1cc9 to your computer and use it in GitHub Desktop.
automapper things
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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