本文整理汇总了C#中Money类的典型用法代码示例。如果您正苦于以下问题:C# Money类的具体用法?C# Money怎么用?C# Money使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Money类属于命名空间,在下文中一共展示了Money类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestOperations
public void TestOperations()
{
var money1 = new Money(12.34, CurrencyCodes.USD);
var money2 = new Money(12.34, CurrencyCodes.ZAR);
Money.Converter = new ConverterMock();
Money.AllowImplicitConversion = true;
// adding oranges to apples gives you apples
var money3 = money1 + money2;
Assert.AreEqual("USD", money3.CurrencyCode);
// left side is ZAR and right side is USD, money3 gets converted back to ZAR
// the same converter should return the same inverted rates
var m1To3 = Money.Converter.GetRate(money1.CurrencyCode, money3.CurrencyCode, DateTime.Now);
var m3To1 = Money.Converter.GetRate(money3.CurrencyCode, money1.CurrencyCode, DateTime.Now);
if (m1To3 == 1d / m3To1)
Assert.AreEqual(money2, money3 - money1);
else
Assert.AreNotEqual(money2, money3 - money1);
// Mix up ZAR and USD. moneys converted only one way
Assert.AreEqual(money1, money3 - money2);
// Should fail if allowImplicitconversion is false (default)
Money.AllowImplicitConversion = false;
try
{
money3 = money1 + money2;
Assert.Fail("Money type exception was not thrown:" + money3.Amount);
}
catch (InvalidOperationException e)
{
Assert.AreEqual("Money type mismatch", e.Message);
}
}
开发者ID:Padhraic,项目名称:Utile.Money,代码行数:34,代码来源:ConversionTest.cs
示例17: ValidateDeposit
public void ValidateDeposit(Money amount)
{
if (amount > _maximumDepositAllowed)
{
throw new ArgumentOutOfRangeException(string.Format("Deposits over {0} are not allowed", _maximumDepositAllowed));
}
}
开发者ID:robukoo,项目名称:SimpleBankingSystem,代码行数:7,代码来源:SimpleAccount.cs
示例18: NinetyPercentOf
public static Money NinetyPercentOf(Money amount)
{
return amount
.Distribute(10)
.Take(9)
.Sum(m => m.Amount);
}
开发者ID:steveevers,项目名称:IndusValley,代码行数:7,代码来源:MoneyUtil.cs
示例19: Run
/// <summary>
/// Runs the code example.
/// </summary>
/// <param name="user">The AdWords user.</param>
/// <param name="businessId">The AdWords Express business id.</param>
/// <param name="promotionId">The promotion id.</param>
public void Run(AdWordsUser user, long businessId, long promotionId) {
// Get the ExpressBusinessService.
ExpressBusinessService businessService = (ExpressBusinessService)
user.GetService(AdWordsService.v201509.ExpressBusinessService);
// Get the PromotionService
PromotionService promotionService = (PromotionService)
user.GetService(AdWordsService.v201509.PromotionService);
// Set the business ID to the service.
promotionService.RequestHeader.expressBusinessId = businessId;
// Update the budget for the promotion
Promotion promotion = new Promotion();
promotion.id = promotionId;
Money newBudget = new Money();
newBudget.microAmount = 2000000;
promotion.budget = newBudget;
PromotionOperation operation = new PromotionOperation();
[email protected] = Operator.SET;
operation.operand = promotion;
try {
Promotion[] updatedPromotions = promotionService.mutate(
new PromotionOperation[] { operation });
Console.WriteLine("Promotion ID {0} for business ID {1} now has budget micro " +
"amount {2}.", promotionId, businessId,
updatedPromotions[0].budget.microAmount);
} catch (Exception e) {
throw new System.ApplicationException("Failed to update promotions.", e);
}
}
开发者ID:markgmarkg,项目名称:googleads-dotnet-lib,代码行数:40,代码来源:UpdatePromotion.cs
示例20: Contract
public Contract(Product product, Money revenue, DateTime whenSigned, long id)
{
_product = product;
Revenue = revenue;
WhenSigned = whenSigned;
_id = id;
}
开发者ID:jonsb,项目名称:RevenueRecognition,代码行数:7,代码来源:Contract.cs
注:本文中的Money类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论