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)); }
public static void ThrowIfCurrencyMismatch(Moneypenny pny, Currency cy) { if (pny.Currency != cy) { throw new InvalidOperationException( Format.Current(Strings_Money.CurrencyMismatch, cy, pny.Currency)); } }
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)); }
public static IEnumerable <Moneypenny> Allocate(Moneypenny penny, int count) { Require.Range(count > 1, nameof(count)); return(AllocateIterator(penny, count)); }