Last active
July 9, 2018 06:40
-
-
Save lbargaoanu/07f21a442a2889e7b9d3f82270136a9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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