Beispiel #1
0
        public static IEnumerable <Moneypenny> AllocateEvenly(Moneypenny penny, int count)
        {
            Require.Range(count > 1, nameof(count));

            var cy = penny.Currency;

            return(from amount in Number.DivideEvenly(penny.Amount, count) select new Moneypenny(amount, cy));
        }
Beispiel #2
0
 public static void ThrowIfCurrencyMismatch(Moneypenny pny, Currency cy)
 {
     if (pny.Currency != cy)
     {
         throw new InvalidOperationException(
                   Format.Current(Strings_Money.CurrencyMismatch, cy, pny.Currency));
     }
 }
Beispiel #3
0
        private static IEnumerable <Moneypenny> AllocateIterator(Moneypenny penny, int count)
        {
            Debug.Assert(count > 1);

            long q    = penny.Amount / count;
            var  part = new Moneypenny(q, penny.Currency);

            for (var i = 0; i < count - 1; i++)
            {
                yield return(part);
            }

            yield return(new Moneypenny(penny.Amount - (count - 1) * q, penny.Currency));
        }
Beispiel #4
0
        public static IEnumerable <Moneypenny> Allocate(Moneypenny penny, int count)
        {
            Require.Range(count > 1, nameof(count));

            return(AllocateIterator(penny, count));
        }