コード例 #1
0
ファイル: ProRataAllocator.cs プロジェクト: shadowca/nmoneys
        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
ファイル: ProRataAllocator.cs プロジェクト: shadowca/nmoneys
        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));
 }