1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| var dictionary = new Dictionary<string, object> { { "Id", 1 }, { "FirstName", "Clark" }, { "LastName", "Kent" } };
var person = Slapper.AutoMapper.MapDynamic<Person>(dictionary);
Console.WriteLine($"Id:{person.Id} FirstName:{person.FirstName} LastName:{person.LastName}");
var dic = new Dictionary<string, object> { { "CustomerId", 1 }, { "FirstName", "Bob" }, { "LastName", "Smith" }, { "Orders_OrderId", 1 }, { "Orders_OrderTotal", 50.50m }, { "Orders_OrderDetails_OrderDetailId", 1 }, { "Orders_OrderDetails_OrderDetailTotal", 25.00m } };
var dic2 = new Dictionary<string, object> { { "CustomerId", 1 }, { "FirstName", "Bob" }, { "LastName", "Smith" }, { "Orders_OrderId", 1 }, { "Orders_OrderTotal", 50.50m }, { "Orders_OrderDetails_OrderDetailId", 2 }, { "Orders_OrderDetails_OrderDetailTotal", 25.50m } };
var list = new List<IDictionary<string, object>> { dic, dic2 };
Slapper.AutoMapper.Cache.ClearInstanceCache();
Slapper.AutoMapper.Configuration.AddIdentifiers(typeof(Customer), new List<string> { "CustomerId", "FirstName", "LastName" });
var customers = (Slapper.AutoMapper.Map<Customer>(list) as IEnumerable<Customer>).ToList(); Console.WriteLine();
public class Person { public int Id; public string FirstName; public string LastName; }
public class Customer { public int CustomerId; public string FirstName; public string LastName; public IList<Order> Orders; }
public class Order { public int OrderId; public decimal OrderTotal; public IList<OrderDetail> OrderDetails; }
public class OrderDetail { public int OrderDetailId; public decimal OrderDetailTotal; }
|