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

Deserialize() public method

Converts the provided dictionary into an object of the specified type.
dictionary
public Deserialize ( object>.IDictionary dictionary ) : GameInfo
dictionary object>.IDictionary An instance of property data stored as name/value pairs.
return GameInfo
        public GameInfo Deserialize(IDictionary<string, object> dictionary)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            GameInfo info = new GameInfo();

            info.Hero = dictionary.ReadValue<string>("Hero");
            info.Child = dictionary.ReadValue<string>("Child");
            info.IsHeroQuest = dictionary.ReadValue<bool>("IsHeroQuest");
            info.IsLinkedGame = dictionary.ReadValue<bool>("IsLinkedGame");
            info.WasGivenFreeRing = dictionary.ReadValue<bool>("WasGivenFreeRing");
            info.GameID = dictionary.ReadValue<short>("GameID");
            info.Rings = (Rings)dictionary.ReadValue<long>("Rings");
            info.Game = dictionary.ReadValue<Game>("Game");
            info.Animal = dictionary.ReadValue<Animal>("Animal");
            info.Behavior = dictionary.ReadValue<ChildBehavior>("Behavior");

            return info;
        }

Usage Example

Ejemplo n.º 1
0
 /// <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);
 }
GameInfoJsonConverter