/// <summary> /// Writes the game info to the specified stream /// </summary> /// <param name="stream">The stream to write to</param> /// <example> /// This example demonstrates creating a .zora save file from a<see cref="GameInfo"/> /// object. If you have access to the file name you will be saving to, as in this /// example, you should consider using the <see cref="Write(string)"/> method instead. /// <code language="C#"> /// GameInfo info = new GameInfo(); /// string file = @"C:\Users\Link\Documents\my_game.zora"; /// using (FileStream outFile = File.Create(file)) /// { /// info.Write(fileStream); /// } /// </code> /// </example> public void Write(Stream stream) { using (var swriter = new StreamWriter(stream)) { GameInfoJsonConverter converter = new GameInfoJsonConverter(); IDictionary<string, object> dict = converter.Serialize(this); string json = SimpleJson.SimpleJson.SerializeObject(dict); swriter.WriteLine(json); } }
/// <summary> /// Parses the specified json. /// </summary> /// <param name="json">The json.</param> /// <returns>A game info object</returns> /// <example> /// <code language="C#"> /// string json = @" /// { /// ""Game"": ""Ages"", /// ""GameID"": 14129, /// ""Hero"": ""Link"", /// ""Child"": ""Pip"", /// ""Animal"": ""Dimitri"", /// ""Behavior"": ""BouncyD"", /// ""IsLinkedGame"": true, /// ""IsHeroQuest"": false, /// ""Rings"": -9222246136947933182 /// }"; /// GameInfo info = GameInfo.Parse(json); /// </code> /// </example> public static GameInfo Parse(string json) { var dict = (IDictionary<string, object>)SimpleJson.SimpleJson.DeserializeObject(json); var converter = new GameInfoJsonConverter(); return converter.Deserialize(dict); }