示例#1
0
        public static Money operator *(decimal m1, Money m2)
        {
            Money newMoney = new Money();
            decimal moneyTemp = 0;

            moneyTemp = m1 * m2.Value;
            newMoney.Value = moneyTemp;
            newMoney.Currency = m2.Currency;

            return newMoney;
        }
示例#2
0
        public static Money operator +(Money m1, Money m2)
        {
            //Handle for +=
            if (m2 == null)
            {
                m2 = new Money(0, m1.Currency);
            }

            ValidateCurrency(m1, m2);
            return new Money(m1.Value + m2.Value, m1.Currency);
        }
示例#3
0
        private static void ValidateCurrency(Money m1, Money m2)
        {
            if (m1 == null)
            {
                throw new Exception("The first argument of money is null.");
            }

            if (m2 == null)
            {
                throw new Exception("The second argument of money is null.");
            }

            if (m1.Currency != m2.Currency)
            {
                throw new Exception("Currency does not match.");
            }
        }