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
IsoCodestringThe ISO 4217 three-letter alphabetic code.
MinorUnitsintThe number of fractional digits in the currency's minor unit.
CashRoundingIncrementdecimalThe smallest physical cash denomination in the major unit, or
0mwhen no special cash rounding is required beyondMinorUnits.IsHistoricboolWhether the currency has been demonetized.
DemonetizedOnDateOnly?The date the currency was withdrawn from circulation, when known.
SuccessorIsoCodestringThe ISO 4217 code of the currency that replaced this one, when defined.
EnglishNamestringThe currency's English-language name in singular Title Case (for example,
"US Dollar"), or an empty string when no name is supplied.NumericCodeintThe ISO 4217 three-digit numeric code (for example,
840forUSD,36forAUD), or0when 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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
IsHistoric
Whether the currency has been demonetized.
public bool IsHistoric { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
IsoCode
The ISO 4217 three-letter alphabetic code.
public string IsoCode { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
SuccessorIsoCode
The ISO 4217 code of the currency that replaced this one, when defined.
public string? SuccessorIsoCode { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
IsoCodestringMinorUnitsintCashRoundingIncrementdecimalIsHistoricboolDemonetizedOnDateOnly?SuccessorIsoCodestringEnglishNamestringNumericCodeint
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
Equals(CurrencyInfo?)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(CurrencyInfo? other)
Parameters
otherCurrencyInfoAn object to compare with this object.
Returns
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
FromCurrencyCode(CurrencyCode)
Resolves a CurrencyCode enum value to its registered CurrencyInfo.
public static CurrencyInfo FromCurrencyCode(CurrencyCode code)
Parameters
codeCurrencyCodeThe ISO 4217 currency code to resolve.
Returns
- CurrencyInfo
The registry entry corresponding to
code.
Exceptions
- ArgumentOutOfRangeException
codeis 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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
ParseCurrencyCode(string)
Resolves an ISO 4217 alphabetic code to the matching CurrencyCode enum member.
public static CurrencyCode ParseCurrencyCode(string isoCode)
Parameters
isoCodestringThe 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
isoCodeis null.- ArgumentException
isoCodedoes 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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
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
isoCodestringThe three-letter uppercase ISO code.
codeCurrencyCodeWhen this method returns true, the matching enum value.
Returns
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
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
Operators
operator ==(CurrencyInfo?, CurrencyInfo?)
public static bool operator ==(CurrencyInfo? left, CurrencyInfo? right)
Parameters
leftCurrencyInforightCurrencyInfo
Returns
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
operator !=(CurrencyInfo?, CurrencyInfo?)
public static bool operator !=(CurrencyInfo? left, CurrencyInfo? right)
Parameters
leftCurrencyInforightCurrencyInfo
Returns
Exceptions
- ArgumentOutOfRangeException
MinorUnitsis less than 0 or greater than 28, orCashRoundingIncrementis negative or is not a whole number of minor units atMinorUnits.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |