Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using ServiceStack;
  4. using ServiceStack.Text;
  5. using System.Collections.Generic;
  6.  
  7. AutoMapping.RegisterConverter((CarRevisionDbo from) => {
  8. var to = from.ConvertTo<CarRevisionDto>(skipConverters:true);
  9. to.PopulateWith(from.Car);
  10. return to;
  11. });
  12.  
  13. public class Car
  14. {
  15. public string Model {get; set;}
  16. public int Year {get; set;}
  17. public int MaxSpeed {get; set;}
  18. }
  19.  
  20. public class TechRevision
  21. {
  22. public bool Ok {get; set;}
  23. public string RevisionDate {get; set;}
  24. }
  25.  
  26. public class CarRevisionDbo
  27. {
  28. public Car Car {get; set;}
  29. public List<TechRevision> TechRevisions {get; set;}
  30. }
  31.  
  32. public class CarRevisionDto
  33. {
  34. public string Model {get; set;}
  35. public int Year {get; set;}
  36. public int MaxSpeed {get; set;}
  37. public List<TechRevision> TechRevisions {get; set;}
  38. }
  39.  
  40. var carRevisions = new []
  41. {
  42. new CarRevisionDbo
  43. {
  44. Car = new Car { Model = "BMW", Year = 2000, MaxSpeed = 190},
  45. TechRevisions = new List<TechRevision>
  46. {
  47. new TechRevision {Ok = true, RevisionDate = "2004"},
  48. new TechRevision {Ok = true, RevisionDate = "2008"}
  49. }
  50. },
  51. new CarRevisionDbo
  52. {
  53. Car = new Car { Model = "VW", Year = 2002, MaxSpeed = 190},
  54. TechRevisions = new List<TechRevision>
  55. {
  56. new TechRevision {Ok = true, RevisionDate = "2006"},
  57. new TechRevision {Ok = true, RevisionDate = "2010"}
  58. }
  59. }
  60. };
  61.  
  62. var converted = carRevisions.ConvertTo<List<CarRevisionDto>>();
  63.  
  64. converted.PrintDump();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement