/// <summary> /// Initialises a new instance from the given Json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the Json data.</param> public PurchaseCurrencyExchangeDefinition(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 CurrencyDefinition((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 Currency to be exchanged.</param> /// <param name="amount">The amount of the Currency to be exchanged.</param> public PurchaseCurrencyExchangeDefinition(CurrencyDefinition item, int amount) { ReleaseAssert.IsNotNull(item, "Item cannot be null."); Item = item; Amount = amount; }
/// <summary> /// Initialises a new instance with the given properties. /// </summary> /// /// <param name="currencyFrom">The conversion from Currency.</param> /// <param name="amountFrom">The from amount.</param> /// <param name="currencyTo">The conversion to Currency.</param> /// <param name="amountTo">The to amount.</param> public ConversionRuleDefinition(CurrencyDefinition currencyFrom, int amountFrom, CurrencyDefinition currencyTo, int amountTo) { ReleaseAssert.IsNotNull(currencyFrom, "Currency From cannot be null."); ReleaseAssert.IsNotNull(currencyTo, "Currency To cannot be null."); CurrencyFrom = currencyFrom; AmountFrom = amountFrom; CurrencyTo = currencyTo; AmountTo = amountTo; }
/// <summary> /// Initialises a new instance from the given Json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the Json data.</param> public ConversionRuleDefinition(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("CurrencyFrom"), "Json is missing required field 'CurrencyFrom'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("AmountFrom"), "Json is missing required field 'AmountFrom'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("CurrencyTo"), "Json is missing required field 'CurrencyTo'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("AmountTo"), "Json is missing required field 'AmountTo'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Currency From if (entry.Key == "CurrencyFrom") { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); CurrencyFrom = new CurrencyDefinition((IDictionary <string, object>)entry.Value); } // Amount From else if (entry.Key == "AmountFrom") { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); AmountFrom = (int)(long)entry.Value; } // Currency To else if (entry.Key == "CurrencyTo") { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); CurrencyTo = new CurrencyDefinition((IDictionary <string, object>)entry.Value); } // Amount To else if (entry.Key == "AmountTo") { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); AmountTo = (int)(long)entry.Value; } } }