MoneyExchangeRateExtensions Class
Definition
Provides extension methods that resolve a dated exchange rate from an IDatedRateProvider and apply it to a Money - the runtime-tagged counterpart of MoneyOfTCurrencyExchangeRateExtensions.
public static class MoneyExchangeRateExtensions
- Inheritance
-
MoneyExchangeRateExtensions
- Inherited Members
Methods
ConvertTo(Money, IDatedRateProvider, string, DateOnly, RateLookupOptions?, MidpointRounding)
Converts amount to targetIsoCode using the rate resolved by
provider for date under options.
public static Money ConvertTo(this Money amount, IDatedRateProvider provider, string targetIsoCode, DateOnly date, RateLookupOptions? options = null, MidpointRounding rounding = MidpointRounding.ToEven)
Parameters
amountMoneyThe amount to convert.
providerIDatedRateProviderThe dated provider that resolves the exchange rate.
targetIsoCodestringThe destination-currency ISO code.
dateDateOnlyThe valuation date.
optionsRateLookupOptionsThe lookup rules to apply.
roundingMidpointRoundingThe rounding mode applied at the destination precision. Defaults to ToEven.
Returns
Exceptions
- ArgumentNullException
providerortargetIsoCodeis null.- ArgumentException
targetIsoCodeis not a three-character uppercase ISO-style code.- KeyNotFoundException
No rate is available for the requested pair under
options.
ConvertToWithRate(Money, IDatedRateProvider, string, DateOnly, RateLookupOptions?, MidpointRounding)
Converts amount to targetIsoCode and returns the converted value
alongside the full RateLookupResult used so callers can audit the selected rate.
public static (Money Target, RateLookupResult Rate) ConvertToWithRate(this Money amount, IDatedRateProvider provider, string targetIsoCode, DateOnly date, RateLookupOptions? options = null, MidpointRounding rounding = MidpointRounding.ToEven)
Parameters
amountMoneyThe amount to convert.
providerIDatedRateProviderThe dated provider that resolves the exchange rate.
targetIsoCodestringThe destination-currency ISO code.
dateDateOnlyThe valuation date.
optionsRateLookupOptionsThe lookup rules to apply.
roundingMidpointRoundingThe rounding mode. Defaults to ToEven.
Returns
- (Money Target, RateLookupResult Rate)
A tuple of the converted amount and the lookup metadata that produced it.
Exceptions
- ArgumentNullException
providerortargetIsoCodeis null.- ArgumentException
targetIsoCodeis not a three-character uppercase ISO-style code.- KeyNotFoundException
No rate is available for the requested pair under
options.
ConvertTo<TTarget>(Money, IDatedRateProvider, DateOnly, RateLookupOptions?, MidpointRounding)
Converts amount to a strongly-typed Money<TCurrency> using the rate resolved by
provider for date under options.
public static Money<TTarget> ConvertTo<TTarget>(this Money amount, IDatedRateProvider provider, DateOnly date, RateLookupOptions? options = null, MidpointRounding rounding = MidpointRounding.ToEven) where TTarget : ICurrency
Parameters
amountMoneyThe amount to convert.
providerIDatedRateProviderThe dated provider that resolves the exchange rate.
dateDateOnlyThe valuation date.
optionsRateLookupOptionsThe lookup rules to apply.
roundingMidpointRoundingThe rounding mode applied at
TTarget's precision. Defaults to ToEven.
Returns
- Money<TTarget>
The converted typed monetary value.
Type Parameters
TTargetThe destination currency type.
Exceptions
- ArgumentNullException
provideris null.- KeyNotFoundException
No rate is available for the requested pair under
options.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |