public static GameModel Load(SupportedSaveFormats format, StreamReader loadLocation) { switch (format) { case SupportedSaveFormats.Json: JsonSerializer jsonSerializer = new JsonSerializer(); return jsonSerializer.Deserialize(loadLocation, typeof(GameModel)) as GameModel; case SupportedSaveFormats.Xml: XmlSerializer xmlSerializer = new XmlSerializer(typeof(GameModel)); return xmlSerializer.Deserialize(loadLocation) as GameModel; default: throw new NotSupportedException("Invalid save format"); } }
public void SaveAs(SupportedSaveFormats format, StreamWriter saveLocation) { switch (format) { case SupportedSaveFormats.Json: JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(saveLocation, this); break; case SupportedSaveFormats.Xml: XmlSerializer xmlSerializer = new XmlSerializer(typeof(GameModel)); xmlSerializer.Serialize(saveLocation, this); break; } }
public static GameModel Load(SupportedSaveFormats format, StreamReader loadLocation) { switch (format) { case SupportedSaveFormats.Json: JsonSerializer jsonSerializer = new JsonSerializer(); return(jsonSerializer.Deserialize(loadLocation, typeof(GameModel)) as GameModel); case SupportedSaveFormats.Xml: XmlSerializer xmlSerializer = new XmlSerializer(typeof(GameModel)); return(xmlSerializer.Deserialize(loadLocation) as GameModel); default: throw new NotSupportedException("Invalid save format"); } }