JsonFileReader.cs 795 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Text.Json;
  2. using Microsoft.Extensions.Configuration;
  3. using System.IO;
  4. using System;
  5. namespace gameapi.Library
  6. {
  7. public class JsonFileReader : IJsonFileReader
  8. {
  9. private string path;
  10. public JsonFileReader()
  11. {
  12. path = GlobalConfiguration.Get().GetSection("gameapi").GetValue<string>("DataPath");
  13. }
  14. public dynamic Read(string filename)
  15. {
  16. var text = File.ReadAllText(filename);
  17. return JsonSerializer.Deserialize<dynamic>(text);
  18. }
  19. public dynamic ReadGameData(string filename)
  20. {
  21. var filePath = path + "/" + filename;
  22. return Read(filePath);
  23. }
  24. }
  25. public interface IJsonFileReader
  26. {
  27. dynamic Read(string filename);
  28. }
  29. }