Esempio n. 1
0
        protected Money(decimal amount, string currencyCode, IcurrencyLookup currencyLookup)
        {
            if (string.IsNullOrEmpty(currencyCode))
            {
                throw new ArgumentNullException(nameof(currencyCode), "Currency code must be specified");
            }

            CurrencyDetails currency = currencyLookup.FindCurrency(currencyCode);

            if (!currency.InUse)
            {
                throw new ArgumentException($"Currency {currencyCode} is not valid");
            }

            if (decimal.Round(amount, currency.DecimalPlaces) != amount)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), $"Amount in {currencyCode} cannot have more than {currency.DecimalPlaces} decimals");
            }

            Amount   = amount;
            Currency = currency;
        }
Esempio n. 2
0
 protected Money(decimal amount, CurrencyDetails currency)
 {
     Amount   = amount;
     Currency = currency;
 }