Table of Contents

MoneyExchangeRateExtensions Class

Definition

Namespace
Bodu.Financial.Extensions
Assembly
Bodu.Financial.dll
Package
Bodu.Financial 1.0.0
Source
MoneyExchangeRateExtensions.ConvertTo.cs

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

amount Money

The amount to convert.

provider IDatedRateProvider

The dated provider that resolves the exchange rate.

targetIsoCode string

The destination-currency ISO code.

date DateOnly

The valuation date.

options RateLookupOptions

The lookup rules to apply.

rounding MidpointRounding

The rounding mode applied at the destination precision. Defaults to ToEven.

Returns

Money

The converted amount as a Money tagged with targetIsoCode.

Exceptions

ArgumentNullException

provider or targetIsoCode is null.

ArgumentException

targetIsoCode is 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

amount Money

The amount to convert.

provider IDatedRateProvider

The dated provider that resolves the exchange rate.

targetIsoCode string

The destination-currency ISO code.

date DateOnly

The valuation date.

options RateLookupOptions

The lookup rules to apply.

rounding MidpointRounding

The 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

provider or targetIsoCode is null.

ArgumentException

targetIsoCode is 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

amount Money

The amount to convert.

provider IDatedRateProvider

The dated provider that resolves the exchange rate.

date DateOnly

The valuation date.

options RateLookupOptions

The lookup rules to apply.

rounding MidpointRounding

The rounding mode applied at TTarget's precision. Defaults to ToEven.

Returns

Money<TTarget>

The converted typed monetary value.

Type Parameters

TTarget

The destination currency type.

Exceptions

ArgumentNullException

provider is null.

KeyNotFoundException

No rate is available for the requested pair under options.

Applies to

ProductVersions
.NET8, 10