Created
February 13, 2017 07:57
-
-
Save lbargaoanu/f23b61dd76ed5a40fb6d3926fb5d4201 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
| public void Main() | |
| { | |
| Mapper.Initialize(cfg => | |
| { | |
| cfg.CreateMap<Source, Destination>(); | |
| cfg.CreateMap<object, DataRow>().ConvertUsing((s, d)=> | |
| { | |
| foreach(var item in Mapper.Map<IDictionary<string, object>>(s)) | |
| { | |
| d[item.Key] = item.Value; | |
| } | |
| return d; | |
| }); | |
| }); | |
| var table = new DataTable("x"); | |
| table.Columns.Add("Value1"); | |
| table.Columns.Add("Value2"); | |
| table.Columns.Add("Value3"); | |
| var dataRow = table.NewRow(); | |
| Mapper.AssertConfigurationIsValid(); | |
| Mapper.Map(new Source { Value = new Dto { Value1 = 1, Value2 = "2", Value3 = 3 }}, new Destination { Value = dataRow }).Dump(); | |
| } | |
| class Dto | |
| { | |
| public int Value1 { get; set; } | |
| public string Value2 { get; set; } | |
| public double Value3 { get; set; } | |
| } | |
| class Source | |
| { | |
| public Dto Value { get; set; } | |
| } | |
| class Destination | |
| { | |
| public DataRow Value { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to use
ConvertUsing((s, d, context) =>and then callcontext.Mapper.Map