123456789101112131415161718192021222324252627282930313233 |
- 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("server").GetValue<string>("DataPath");
- }
- public void Save(string filename, dynamic data)
- {
- var serializedData = JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true });
- File.WriteAllText(filename, serializedData);
- }
- public void SaveGameData(string filename, dynamic data)
- {
- var filePath = path + "/" + filename;
- Save(filePath, data);
- }
- }
- public interface IJsonFileSaver
- {
- void Save(string filename, dynamic data);
- }
- }
|