예제 #1
0
        public Allocation Allocate(RatioCollection ratios)
        {
            Money[] results = Money.Zero(_currency, ratios.Count);
            //allocated = Money.Zero(_currency);

            for (var i = 0; i < ratios.Count; i++)
            {
                var share = ratios[i].ApplyTo(_toAllocate.Amount);
                share      = _currency.Round(share);
                results[i] = new Money(share, _currency);
            }
            return(new Allocation(_toAllocate, results));
        }
예제 #2
0
        public Money[] Allocate(RatioCollection ratios, out Money allocated)
        {
            var results = initResults(ratios.Count);

            allocated = Money.Zero(_currency);

            for (var i = 0; i < ratios.Count; i++)
            {
                var share = ratios[i].ApplyTo(_toAllocate.Amount);
                share      = _currency.Round(share);
                results[i] = new Money(share, _currency);
                allocated += results[i];
            }
            return(results);
        }
예제 #3
0
        public static Allocation Allocate(this Money money, RatioCollection ratios, IRemainderAllocator allocator)
        {
            Guard.AgainstNullArgument(nameof(ratios), ratios);

            if (money.notEnoughToAllocate())
            {
                return(Allocation.Zero(money, ratios.Count));
            }

            Allocation allocated = new ProRataAllocator(money)
                                   .Allocate(ratios);

            allocated = money.allocateRemainderIfNeeded(allocator, allocated);

            return(allocated);
        }
예제 #4
0
 public static Allocation Allocate(this Money money, RatioCollection ratios)
 {
     return(money.Allocate(ratios, RemainderAllocator.FirstToLast));
 }