Table of Contents

CurrencyInfo Class

Definition

Namespace
Bodu.Financial.Currencies
Assembly
Bodu.Financial.dll
Package
Bodu.Financial 1.3.0
Source
CurrencyInfo.cs

Carries the runtime metadata of a currency: ISO 4217 code, minor-unit precision, cash-rounding increment, and historicity / successor information.

public sealed record CurrencyInfo : IEquatable<CurrencyInfo>
Inheritance
CurrencyInfo
Implements
Inherited Members
Extension Methods

Remarks

This record is the runtime counterpart of an ICurrency tag type. The runtime-tagged Money and the MoneyBag aggregate operate against CurrencyRegistry entries of this shape so they can handle currencies the consumer learns about at runtime (for example, from a deserialized JSON payload).

Constructors

CurrencyInfo(string, int, decimal, bool, DateOnly?, string?, string, int)

Carries the runtime metadata of a currency: ISO 4217 code, minor-unit precision, cash-rounding increment, and historicity / successor information.

public CurrencyInfo(string IsoCode, int MinorUnits, decimal CashRoundingIncrement, bool IsHistoric, DateOnly? DemonetizedOn, string? SuccessorIsoCode, string EnglishName = "", int NumericCode = 0)

Parameters

IsoCode string

The ISO 4217 three-letter alphabetic code.

MinorUnits int

The number of fractional digits in the currency's minor unit.

CashRoundingIncrement decimal

The smallest physical cash denomination in the major unit, or 0m when no special cash rounding is required beyond MinorUnits.

IsHistoric bool

Whether the currency has been demonetized.

DemonetizedOn DateOnly?

The date the currency was withdrawn from circulation, when known.

SuccessorIsoCode string

The ISO 4217 code of the currency that replaced this one, when defined.

EnglishName string

The currency's English-language name in singular Title Case (for example, "US Dollar"), or an empty string when no name is supplied.

NumericCode int

The ISO 4217 three-digit numeric code (for example, 840 for USD, 36 for AUD), or 0 when the currency is custom or the numeric code is unknown.

Remarks

This record is the runtime counterpart of an ICurrency tag type. The runtime-tagged Money and the MoneyBag aggregate operate against CurrencyRegistry entries of this shape so they can handle currencies the consumer learns about at runtime (for example, from a deserialized JSON payload).

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

Properties

AlternativeSymbols

Gets alternative symbols that may also denote the currency.

public IReadOnlyList<string> AlternativeSymbols { get; init; }

Property Value

IReadOnlyList<string>

The additional symbols recognized for the currency.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

CashRoundingIncrement

Gets the smallest physical cash denomination in the major unit, or 0m when no special cash rounding is required beyond MinorUnits.

public decimal CashRoundingIncrement { get; init; }

Property Value

decimal

The cash-rounding increment: zero, or a positive whole number of minor units.

Remarks

The constructor, an object initializer and a with expression all apply the check, which is the rule CashRoundingIncrement follows for a currency tag type.

Exceptions

ArgumentOutOfRangeException

The value is negative, or is not a whole number of minor units at MinorUnits.

DemonetizedOn

The date the currency was withdrawn from circulation, when known.

public DateOnly? DemonetizedOn { get; init; }

Property Value

DateOnly?

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

EnglishName

The currency's English-language name in singular Title Case (for example, "US Dollar"), or an empty string when no name is supplied.

public string EnglishName { get; init; }

Property Value

string

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

InternationalSymbol

Gets the currency's internationally disambiguated symbol (for example, "US$" or "R$"), or an empty string when none is supplied.

public string InternationalSymbol { get; init; }

Property Value

string

The unambiguous symbol used where the bare Symbol would be ambiguous.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

IsHistoric

Whether the currency has been demonetized.

public bool IsHistoric { get; init; }

Property Value

bool

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

IsoCode

The ISO 4217 three-letter alphabetic code.

public string IsoCode { get; init; }

Property Value

string

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

MinorUnits

Gets the number of fractional digits in the currency's minor unit.

public int MinorUnits { get; init; }

Property Value

int

The minor-unit precision, from 0 to 28.

Remarks

The constructor, an object initializer and a with expression all apply the checks, so every CurrencyInfo carries a scale that decimal can represent and a cash-rounding increment that scale can hold. An initializer that sets both this property and CashRoundingIncrement checks each against the other's value when it is set, so set the increment first when the new minor units cannot hold the current one.

Exceptions

ArgumentOutOfRangeException

The value is less than 0 or greater than 28, or CashRoundingIncrement is not a whole number of minor units at the value; the exception then names CashRoundingIncrement.

NativeName

Gets the currency's name in its primary native language, or an empty string when none is supplied.

public string NativeName { get; init; }

Property Value

string

The localized currency name.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

NumericCode

The ISO 4217 three-digit numeric code (for example, 840 for USD, 36 for AUD), or 0 when the currency is custom or the numeric code is unknown.

public int NumericCode { get; init; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

RegionCodes

Gets the ISO 3166 region codes in which the currency is used.

public IReadOnlyList<string> RegionCodes { get; init; }

Property Value

IReadOnlyList<string>

The regions associated with the currency.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

SuccessorIsoCode

The ISO 4217 code of the currency that replaced this one, when defined.

public string? SuccessorIsoCode { get; init; }

Property Value

string

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

Symbol

Gets the currency's primary symbol (for example, "$" or "€"), or an empty string when none is supplied.

public string Symbol { get; init; }

Property Value

string

The display symbol associated with the currency.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

Methods

Deconstruct(out string, out int, out decimal, out bool, out DateOnly?, out string?, out string, out int)

public void Deconstruct(out string IsoCode, out int MinorUnits, out decimal CashRoundingIncrement, out bool IsHistoric, out DateOnly? DemonetizedOn, out string? SuccessorIsoCode, out string EnglishName, out int NumericCode)

Parameters

IsoCode string
MinorUnits int
CashRoundingIncrement decimal
IsHistoric bool
DemonetizedOn DateOnly?
SuccessorIsoCode string
EnglishName string
NumericCode int

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

Equals(CurrencyInfo?)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(CurrencyInfo? other)

Parameters

other CurrencyInfo

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

FromCurrencyCode(CurrencyCode)

Resolves a CurrencyCode enum value to its registered CurrencyInfo.

public static CurrencyInfo FromCurrencyCode(CurrencyCode code)

Parameters

code CurrencyCode

The ISO 4217 currency code to resolve.

Returns

CurrencyInfo

The registry entry corresponding to code.

Exceptions

ArgumentOutOfRangeException

code is None or is not a defined CurrencyCode member.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

ParseCurrencyCode(string)

Resolves an ISO 4217 alphabetic code to the matching CurrencyCode enum member.

public static CurrencyCode ParseCurrencyCode(string isoCode)

Parameters

isoCode string

The three-letter uppercase ISO code.

Returns

CurrencyCode

The CurrencyCode member matching isoCode.

Remarks

The throwing counterpart of TryGetCurrencyCode(string, out CurrencyCode), and the canonical boundary helper for turning an externally supplied ISO string into the stored enum representation.

Exceptions

ArgumentNullException

isoCode is null.

ArgumentException

isoCode does not match any active or historic currency in CurrencyCode.

ToCurrencyCode()

Returns the CurrencyCode enum value corresponding to this CurrencyInfo.

public CurrencyCode ToCurrencyCode()

Returns

CurrencyCode

The matching enum member.

Exceptions

InvalidOperationException

The currency's IsoCode does not correspond to any CurrencyCode member (for example, a currency outside the shipped ISO 4217 catalog).

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

TryGetCurrencyCode(string, out CurrencyCode)

Attempts to resolve an ISO 4217 alphabetic code to the matching CurrencyCode enum member.

public static bool TryGetCurrencyCode(string isoCode, out CurrencyCode code)

Parameters

isoCode string

The three-letter uppercase ISO code.

code CurrencyCode

When this method returns true, the matching enum value.

Returns

bool

true when isoCode matches a currency in the enum - active or historic; otherwise false.

Remarks

The match is case-sensitive: only the canonical three-uppercase-letter ISO form resolves successfully. The None sentinel and any code outside the shipped catalog surface here as false.

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

Operators

operator ==(CurrencyInfo?, CurrencyInfo?)

public static bool operator ==(CurrencyInfo? left, CurrencyInfo? right)

Parameters

left CurrencyInfo
right CurrencyInfo

Returns

bool

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

operator !=(CurrencyInfo?, CurrencyInfo?)

public static bool operator !=(CurrencyInfo? left, CurrencyInfo? right)

Parameters

left CurrencyInfo
right CurrencyInfo

Returns

bool

Exceptions

ArgumentOutOfRangeException

MinorUnits is less than 0 or greater than 28, or CashRoundingIncrement is negative or is not a whole number of minor units at MinorUnits.

Applies to

ProductVersions
.NET8, 10