当前位置: 首页>>代码示例>>C#>>正文


C# Money类代码示例

本文整理汇总了C#中Money的典型用法代码示例。如果您正苦于以下问题:C# Money类的具体用法?C# Money怎么用?C# Money使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Money类属于命名空间,在下文中一共展示了Money类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateRandomAccountCollection

        private EntityCollection GenerateRandomAccountCollection()
        {
            var collection = new List<Entity>();
            for (var i = 0; i < 10; i++)
            {
                var rgn = new Random((int)DateTime.Now.Ticks);
                var entity = new Entity("account");
                entity["accountid"] = entity.Id = Guid.NewGuid();
                entity["address1_addressid"] = Guid.NewGuid();
                entity["modifiedon"] = DateTime.Now;
                entity["lastusedincampaign"] = DateTime.Now;
                entity["donotfax"] = rgn.NextBoolean();
                entity["new_verybignumber"] = rgn.NextInt64();
                entity["exchangerate"] = rgn.NextDecimal();
                entity["address1_latitude"] = rgn.NextDouble();
                entity["numberofemployees"] = rgn.NextInt32();
                entity["primarycontactid"] = new EntityReference("contact", Guid.NewGuid());
                entity["revenue"] = new Money(rgn.NextDecimal());
                entity["ownerid"] = new EntityReference("systemuser", Guid.NewGuid());
                entity["industrycode"] = new OptionSetValue(rgn.NextInt32());
                entity["name"] = rgn.NextString(15);
                entity["description"] = rgn.NextString(300);
                entity["statecode"] = new OptionSetValue(rgn.NextInt32());
                entity["statuscode"] = new OptionSetValue(rgn.NextInt32());
                collection.Add(entity);
            }

            return new EntityCollection(collection);
        }
开发者ID:guusvanw,项目名称:Guus.Xrm,代码行数:29,代码来源:GenericXrmServiceTest.cs

示例2: DivisionOfMoneyObejcts_ShouldReturnWallet

 public void DivisionOfMoneyObejcts_ShouldReturnWallet()
 {
     var money1 = new Money<long>(42);
     var money2 = new Money<long>(1000);
     var actual = money1 / money2;
     actual.ShouldBeAssignableTo<Wallet<long>>();
 }
开发者ID:zpbappi,项目名称:money,代码行数:7,代码来源:BinaryOperationBetweenMoneyObjectsTest.cs

示例3: MoneyHasValueEquality

        public void MoneyHasValueEquality()
        {
            var money1 = new Money(101.5M);
            var money2 = new Money(101.5M);

            money2.ShouldBe(money1);
        }
开发者ID:madhon,项目名称:money-type-for-the-clr,代码行数:7,代码来源:MoneyTests.cs

示例4: Round

        internal Money Round(Money money, int decimalPlaces)
        {
            decimal amount = money.Amount;
            int factor = (int) Math.Pow(10, decimalPlaces);

            // split the amount into integral and fraction parts
            decimal integral = Math.Truncate(money.Amount);
            decimal fraction = amount-integral;

            // raise the fraction by the number of decimal places to which we want to round,
            // so that we can apply integer rounding
            decimal raisedFraction = Decimal.Multiply(fraction, factor);

            // pass the raisedFraction to a template method to do the rounding according to the RoundingStrategy
            decimal roundedFraction = CalculateRoundedAmount(raisedFraction);

            // shift the decimal to the left again, by the number of decimal places
            decimal resultFraction = Decimal.Divide(roundedFraction, factor);

            // add the original integral and the rounded resultFraction back together
            decimal roundedAmount = integral + resultFraction;

            // return the result
            return new Money(money.Currency, roundedAmount, money.RoundingMode, (DecimalPlaces)money.DecimalPlaces);
        }
开发者ID:hermanpotgieter,项目名称:MoneyAndCurrency,代码行数:25,代码来源:RoundingStrategy.cs

示例5: MoneyFractionalAmountWithOverflowAdditionIsCorrect

        public void MoneyFractionalAmountWithOverflowAdditionIsCorrect()
        {
            var money1 = new Money(100.999M);
            var money2 = new Money(0.9M);

            Assert.Equal(new Money(101.899m), money1 + money2);
        }
开发者ID:smarkets,项目名称:IronSmarkets,代码行数:7,代码来源:MoneyTests.cs

示例6: MoneyFractionalAmountAdditionIsCorrect

        public void MoneyFractionalAmountAdditionIsCorrect()
        {
            var money1 = new Money(100.00m);
            var money2 = new Money(0.01m);

            Assert.Equal(new Money(100.01m), money1 + money2);
        }
开发者ID:smarkets,项目名称:IronSmarkets,代码行数:7,代码来源:MoneyTests.cs

示例7: DataBind

 public override void DataBind()
 {
     var splitLineItems = Shipment.GetShipmentLineItems(SplitShipment);
     var billingCurrency = CartHelper.Cart.BillingCurrency;
     if (splitLineItems != null)
     {
         OrderSubTotalLineItems.Text = new Money(splitLineItems.ToArray().Sum(x => x.ExtendedPrice) +
             splitLineItems.ToArray().Sum(x => x.OrderLevelDiscountAmount), billingCurrency).ToString();
     }
     if (SplitShipment != null)
     {
         string discountMessage = String.Empty;
         var shippingDiscountsTotal = CalculateShippingDiscounts(SplitShipment, billingCurrency, out discountMessage);
         var shippingCostSubTotal = CalculateShippingCostSubTotal(SplitShipment, CartHelper);
         shippingDiscount.Text = shippingDiscountsTotal.ToString();
         ShippingDiscountsMessage.Text = discountMessage;
         shippingTotal.Text = (shippingCostSubTotal).ToString();
     }
     else
     {
         string zeroMoney = new Money(0, SiteContext.Current.Currency).ToString();
         shippingDiscount.Text = zeroMoney;
         shippingTotal.Text = zeroMoney;
     }
 }
开发者ID:radulazariciu,项目名称:Internship,代码行数:25,代码来源:OrderSubtotalMultiView.ascx.cs

示例8: makeTransfer

 public Transfer makeTransfer(string counterAccount, Money amount)
 {
     // 1. Assuming result is 9-digit bank account number, validate 11-test:
     int sum = 0; // <1>
     for (int i = 0; i < counterAccount.Length; i++)
     {
         sum = sum + (9 - i) * (int)Char.GetNumericValue(
             counterAccount[i]);
     }
     if (sum % 11 == 0)
     {
         // 2. Look up counter account and make transfer object:
         CheckingAccount acct = Accounts.FindAcctByNumber(counterAccount);
         Transfer result = new Transfer(this, acct, amount); // <2>
         // 3. Check whether withdrawal is to registered counter account:
         if (result.CounterAccount.Equals(this.RegisteredCounterAccount))
         {
             return result;
         }
         else
         {
             throw new BusinessException("Counter-account not registered!");
         }
     }
     else
     {
         throw new BusinessException("Invalid account number!!");
     }
 }
开发者ID:oreillymedia,项目名称:building_maintainable_software,代码行数:29,代码来源:SavingsAccount.cs

示例9: CurrencyCodeShouldBeCaseIgnorant

        public void CurrencyCodeShouldBeCaseIgnorant(string currency)
        {
            const Currency expectedCurrency = Currency.AUD;
            var money = new Money(42, currency);

            money.Currency.ShouldBe(expectedCurrency);
        }
开发者ID:zpbappi,项目名称:money,代码行数:7,代码来源:ConstructionTest.cs

示例10: WhenDestinationCurrencyIsEmpty_ShouldThrow

 public void WhenDestinationCurrencyIsEmpty_ShouldThrow()
 {
     var m1 = new Money<decimal>(123, "USD");
     var m2 = new Money<decimal>(1, "AUD");
     var wallet = m1 + m2;
     Should.Throw<ArgumentNullException>(() => wallet.Evaluate(this.currencyConverter, null));
 }
开发者ID:zpbappi,项目名称:money,代码行数:7,代码来源:BinaryOperationWithConverterTest.cs

示例11: WhenCurrencyConverterIsNull_ShouldThrow

 public void WhenCurrencyConverterIsNull_ShouldThrow()
 {
     var m1 = new Money<int>(123, "USD");
     var m2 = new Money<int>(1, "AUD");
     var wallet = m1 + m2;
     Should.Throw<ArgumentNullException>(() => wallet.Evaluate(null, "AUD"));
 }
开发者ID:zpbappi,项目名称:money,代码行数:7,代码来源:BinaryOperationWithConverterTest.cs

示例12: Price

 /// <summary>
 /// Initializes a new instance of the <see cref="T:B4F.TotalGiro.Instruments.Price">Price</see> class.
 /// </summary>
 /// <param name="money">This is the amount that one particular instrument to which the price belongs would cost</param>
 /// <param name="instrument">The instrument to which the price belongs</param>
 public Price(Money money, IInstrument instrument)
 {
     this.quantity = money.Quantity;
     this.underlying = (ICurrency)money.Underlying;
     this.instrument = instrument;
     this.XRate = money.XRate;
 }
开发者ID:kiquenet,项目名称:B4F,代码行数:12,代码来源:Price.cs

示例13: opInequality_Money_Money

        public void opInequality_Money_Money()
        {
            var obj = new Money(new Currency("€", 2), 1.23m);
            var comparand = new Money(new Currency("£", 2), 1.23m);

            Assert.True(obj != comparand);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:Money.Facts.cs

示例14: Bid

        public void Bid(Guid auctionId, Guid memberId, decimal amount)
        {
            try
            {
                using (DomainEvents.Register(OutBid()))
                using (DomainEvents.Register(BidPlaced()))
                {
                    var auction = _auctionRepository.FindBy(auctionId);

                    var bidAmount = new Money(amount);

                    auction.PlaceBidFor(new Bid(memberId, bidAmount, _clock.Time()), _clock.Time());

                    _auctionRepository.Save(auction);
                }

                _unitOfWork.Commit();
            }
            catch (ConcurrencyException ex)
            {
                _unitOfWork.Clear();

                Bid(auctionId, memberId, amount);
            }            
        }
开发者ID:elbandit,项目名称:PPPDDD,代码行数:25,代码来源:BidOnAuction.cs

示例15: AdditionOfMoneyObejcts_ShouldReturnWallet

 public void AdditionOfMoneyObejcts_ShouldReturnWallet()
 {
     var money1 = new Money<int>(42);
     var money2 = new Money<int>(1000);
     var actual = money1 + money2;
     actual.ShouldBeAssignableTo<Wallet<int>>();
 }
开发者ID:zpbappi,项目名称:money,代码行数:7,代码来源:BinaryOperationBetweenMoneyObjectsTest.cs


注:本文中的Money类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。