FixedRateTable Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.dll
- Package
- Bodu.Financial 1.3.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 or validating the code. 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
Exceptions
- ArgumentNullException
Thrown if
ratesis 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 or names no CurrencyCode member.
- ArgumentOutOfRangeException
Thrown if any rate in
ratesis 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
fromIsoCodestringThe source currency's ISO 4217 code.
toIsoCodestringThe destination currency's ISO 4217 code.
Returns
- decimal
The rate.
Exceptions
- ArgumentNullException
Thrown if
fromIsoCodeortoIsoCodeis null.- ArgumentException
Thrown if either ISO code is not a three-character uppercase ASCII code or names no CurrencyCode member.
- KeyNotFoundException
No rate is available for the requested pair.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |