/// <summary> /// Initialises a new instance from the given Json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the Json data.</param> public PurchaseInventoryExchangeDefinition(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Item"), "Json is missing required field 'Item'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Amount"), "Json is missing required field 'Amount'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Item if (entry.Key == "Item") { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); Item = new InventoryDefinition((IDictionary <string, object>)entry.Value); } // Amount else if (entry.Key == "Amount") { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); Amount = (int)(long)entry.Value; } // An error has occurred. else { #if DEBUG throw new ArgumentException("Input Json contains an invalid field."); #endif } } }
/// <summary> /// Initialises a new instance with the given properties. /// </summary> /// /// <param name="item">The Inventory item to be exchanged.</param> /// <param name="amount">The number of the Inventory items to be exchanged.</param> public PurchaseInventoryExchangeDefinition(InventoryDefinition item, int amount) { ReleaseAssert.IsNotNull(item, "Item cannot be null."); Item = item; Amount = amount; }