Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 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. public class Car
  8. {
  9. public string Model {get; set;}
  10. public int Year {get; set;}
  11. public int MaxSpeed {get; set;}
  12. }
  13.  
  14. public class TechRevision
  15. {
  16. public bool Ok {get; set;}
  17. public string RevisionDate {get; set;}
  18. }
  19.  
  20. public class CarRevisionDbo
  21. {
  22. public Car Car {get; set;}
  23. public List<TechRevision> TechRevisions {get; set;}
  24. }
  25.  
  26. public class CarRevisionDto
  27. {
  28. public string Model {get; set;}
  29. public int Year {get; set;}
  30. public int MaxSpeed {get; set;}
  31. public List<TechRevision> TechRevisions {get; set;}
  32. }
  33.  
  34. var carRevisions = new []
  35. {
  36. new CarRevisionDbo
  37. {
  38. Car = new Car { Model = "BMW", Year = 2000, MaxSpeed = 190},
  39. TechRevisions = new List<TechRevision>
  40. {
  41. new TechRevision {Ok = true, RevisionDate = "2004"},
  42. new TechRevision {Ok = true, RevisionDate = "2008"}
  43. }
  44. },
  45. new CarRevisionDbo
  46. {
  47. Car = new Car { Model = "VW", Year = 2002, MaxSpeed = 190},
  48. TechRevisions = new List<TechRevision>
  49. {
  50. new TechRevision {Ok = true, RevisionDate = "2006"},
  51. new TechRevision {Ok = true, RevisionDate = "2010"}
  52. }
  53. }
  54. };
  55.  
  56. var converted = carRevisions.ConvertTo<List<CarRevisionDto>>();
  57.  
  58.  
  59. System.Console.WriteLine(converted.ToJson());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement