Class4.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Newtonsoft.Json;
  2. using System;
  3. using WpfApp1;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.Serialization;
  8. using System.Runtime.Serialization.Json;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace WpfApp1.model
  12. {
  13. public class JSONDataProvider : LocalDataProvider, IDataProvider
  14. {
  15. private List<CarWithStringDates> _CarList;
  16. public JSONDataProvider()
  17. {
  18. using (var sr = new StreamReader("./Test.json"))
  19. {
  20. _CarList = JsonConvert.DeserializeObject<CarWithStringDates[]>(sr.ReadToEnd()).ToList();
  21. }
  22. }
  23. public new IEnumerable<cars> getCars()
  24. {
  25. return _CarList.Select(p => new cars
  26. {
  27. name = p.name,
  28. year = p.year,
  29. price = p.price,
  30. color = p.color,
  31. defects = p.defects,
  32. photo = p.photo,
  33. dateOfLastSTO = p.dateOfLastSTO == null ? null : DateOnly.Parse(p.dateOfLastSTO),
  34. });
  35. }
  36. }
  37. }