1234567891011121314151617181920212223242526 |
- using System.Text.Json;
- using Microsoft.Extensions.Configuration;
- using System.IO;
- namespace gameapi.Library
- {
- public class JsonFileSaver : IJsonFileSaver
- {
- private string path;
- public JsonFileSaver()
- {
- path = GlobalConfiguration.Get().GetSection("gameapi").GetValue<string>("DataPath");
- }
- public void Save(string filename, dynamic data)
- {
- var filePath = path + "/" + filename;
- File.WriteAllText(filePath, JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true }));
- }
- }
- public interface IJsonFileSaver
- {
- void Save(string filename, dynamic data);
- }
- }
|