Zyrenth.Zora.GameInfoJsonConverter.Serialize C# (CSharp) Method

Serialize() public method

Builds a dictionary of name/value pairs.
Invalid type;obj
public Serialize ( GameInfo info ) : object>.IDictionary
info GameInfo
return object>.IDictionary
        public IDictionary<string, object> Serialize(GameInfo info)
        {
            if (info == null)
                throw new ArgumentNullException("info cannot be null");

            var dict = new Dictionary<string, object>();

            dict["Hero"] = info.Hero;
            dict["Child"] = info.Child;
            dict["GameID"] = info.GameID;
            dict["Game"] = info.Game.ToString();
            dict["Animal"] = info.Animal.ToString();
            dict["Behavior"] = info.Behavior.ToString();
            dict["IsLinkedGame"] = info.IsLinkedGame;
            dict["IsHeroQuest"] = info.IsHeroQuest;
            dict["WasGivenFreeRing"] = info.WasGivenFreeRing;
            dict["Rings"] = (long)info.Rings;

            return dict;
        }

Usage Example

Example #1
0
 /// <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);
     }
 }
GameInfoJsonConverter