Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Last active July 9, 2018 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbargaoanu/07f21a442a2889e7b9d3f82270136a9a to your computer and use it in GitHub Desktop.
Save lbargaoanu/07f21a442a2889e7b9d3f82270136a9a to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<ClassFrom, ClassTo>(MemberList.None).ReverseMap();
});
config.AssertConfigurationIsValid();
config.FindTypeMapFor(typeof(ClassTo), typeof(ClassFrom)).ConfiguredMemberList.Dump();
var mapper = config.CreateMapper();
var fromList = new List<ClassFrom>
{
new ClassFrom { UnmappedSource = 1, Foo = "foo1", Bar = "Bar1" },
new ClassFrom { UnmappedSource = 2, Foo = "foo2", Bar = "Bar2" }
};
try{
var destination = mapper.Map<List<ClassTo>>(fromList).Dump();
mapper.Map<List<ClassFrom>>(destination).Dump();
}catch(Exception ex){
ex.ToString().Dump();
}
}
class ClassFrom
{
public int UnmappedSource { get; set; }
public string Foo { get; set; }
public string Bar { get; set; }
}
class ClassTo
{
public int UnmappedDestination { get; set; }
public string Foo { get; set; }
public string Bar { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment