You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
707 B
27 lines
707 B
using System.Runtime.Serialization;
|
|
using QwirkleClassLibrary.Games;
|
|
|
|
namespace QwirkleClassLibrary.Persistences;
|
|
|
|
public class GamePersistenceJson : IGamePersistence
|
|
{
|
|
public void SaveGame(Game game)
|
|
{
|
|
var serializer = new DataContractSerializer(typeof(Game));
|
|
|
|
using (Stream writer = File.Create("Game.json"))
|
|
{
|
|
serializer.WriteObject(writer, game);
|
|
}
|
|
}
|
|
|
|
public Game LoadGame()
|
|
{
|
|
var serializer = new DataContractSerializer(typeof(Game));
|
|
|
|
using (Stream reader = File.OpenRead("Game.json"))
|
|
{
|
|
return serializer.ReadObject(reader) as Game ?? throw new InvalidOperationException();
|
|
}
|
|
}
|
|
} |