JsonFileReader.cs 587 B

1234567891011121314151617181920212223
  1. using System.Text.Json;
  2. using Microsoft.Extensions.Configuration;
  3. using System.IO;
  4. using System;
  5. namespace sera_slackbot.Library
  6. {
  7. public class JsonFileReader
  8. {
  9. private string path;
  10. public JsonFileReader(IConfiguration config)
  11. {
  12. path = config.GetSection("Persistence").GetValue<string>("Path");
  13. }
  14. public dynamic Read(string filename)
  15. {
  16. var filePath = path + "/" + filename;
  17. var text = File.ReadAllText(filePath);
  18. return JsonSerializer.Deserialize<dynamic>(text);
  19. }
  20. }
  21. }