示例#1
0
        protected Money(decimal amount, string currencyCode, ICurrencyLookup currencyLookup)
        {
            if (string.IsNullOrEmpty(currencyCode))
            {
                throw new ArgumentException("Currency code must be specified", nameof(currencyCode));
            }
            var currency = currencyLookup.FindCurrency(currencyCode);

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

            if (decimal.Round(amount, currency.DecimalPlaces) != amount)
            {
                throw new ArgumentException($"Amount cannot have more than {currency.DecimalPlaces} decimals", nameof(amount));
            }
            Amount   = amount;
            Currency = currency;
        }
示例#2
0
 protected Money(decimal amount, CurrencyDetails currency)
 {
     Amount   = amount;
     Currency = currency;
 }