Table of Contents

FixedRateTable Class

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.dll
Package
Bodu.Financial 1.0.0
Source
FixedRateTable.cs

An IRateProvider backed by a fixed dictionary of (from, to) → rate mappings.

public sealed class FixedRateTable : IRateProvider
Inheritance
FixedRateTable
Implements
Inherited Members
Extension Methods

Remarks

Same-currency lookups return 1m without consulting the table. When a direct (from, to) pair is missing the provider also tries the inverse (to, from) pair and, if found, returns 1 / rate. This is the convention most FX feeds use to keep the table minimal.

The table is immutable after construction. The constructor copies the supplied rates into a FrozenDictionary<TKey, TValue>, so subsequent mutations to the source collection cannot affect the table. Each entry's ISO codes and rate are validated at construction time.

Constructors

FixedRateTable(IReadOnlyDictionary<(string From, string To), decimal>)

Initializes a new instance of the FixedRateTable class from the supplied dictionary of (from, to) → rate mappings, validating each entry and copying the contents into an immutable store.

public FixedRateTable(IReadOnlyDictionary<(string From, string To), decimal> rates)

Parameters

rates IReadOnlyDictionary<(string From, string To), decimal>

The rate table to copy.

Exceptions

ArgumentNullException

Thrown if rates is null, or if any key tuple contains a null ISO code.

ArgumentException

Thrown if any key tuple's ISO code is not a three-character uppercase ASCII code.

ArgumentOutOfRangeException

Thrown if any rate in rates is zero or negative.

Methods

GetRate(string, string)

Returns the exchange rate that converts one unit of fromIsoCode to units of toIsoCode.

public decimal GetRate(string fromIsoCode, string toIsoCode)

Parameters

fromIsoCode string

The source currency's ISO 4217 code.

toIsoCode string

The destination currency's ISO 4217 code.

Returns

decimal

The rate.

Exceptions

KeyNotFoundException

No rate is available for the requested pair.

Applies to

ProductVersions
.NET8, 10