Beispiel #1
0
        /// <summary>
        /// THis will only clone: Positivemmoney, NonNegativeMoney and Money types.
        /// </summary>
        /// <param name="original"></param>
        /// <param name="currencyToClone"></param>
        /// <returns></returns>
        public static Money CopyToMoney(MoneyBase original, Currency currencyToClone)
        {
            var amount = GetZeroAmount(currencyToClone.Value);

            // || original as PositiveMoney != null || original as NonNegativeMoney != null
            if (null != original.currency)
            {
                if (original.currency.Value == currencyToClone.Value)
                {
                    if (original as Money != null)
                    {
                        amount.amount = ((Money)original).amount;
                    }
                    else if (original as NonNegativeMoney != null)
                    {
                        amount.amount = ((NonNegativeMoney)original).amount;
                    }
                    else if (original as PositiveMoney != null)
                    {
                        amount.amount = ((PositiveMoney)original).amount;
                    }
                }
            }
            amount.id = original.id;
            return(amount);
        }
Beispiel #2
0
        public static Money CopyToMoney(MoneyBase original)
        {
            var cloned = new Money();

            if (original as Money != null)
            {
                cloned.amount = ((Money)original).amount;
            }
            else if (original as NonNegativeMoney != null)
            {
                cloned.amount = ((NonNegativeMoney)original).amount;
            }
            else if (original as PositiveMoney != null)
            {
                cloned.amount = ((PositiveMoney)original).amount;
            }
            if (null != original.currency)
            {
                cloned.currency = new Currency();
                if (null != original.currency.currencyScheme)
                {
                    cloned.currency.currencyScheme = original.currency.currencyScheme;
                }
                if (null != original.currency.Value)
                {
                    cloned.currency.Value = original.currency.Value;
                }
            }
            cloned.id = original.id;
            return(cloned);
        }
Beispiel #3
0
        public static Money Normalise(MoneyBase originalMoney, bool isPayerBase)
        {
            var money = CopyToMoney(originalMoney);//TODO this does nothing

            //money.amount = System.Math.Abs(money.amount);
            if (isPayerBase)
            {
                money.amount = -1 * money.amount;
            }
            return(money);
        }