CurrencyPair Struct
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.dll
- Package
- Bodu.Financial 1.0.0
- Source
- CurrencyPair.cs
Represents an ordered pair of currencies that identifies the direction of an exchange-rate quotation.
public readonly struct CurrencyPair : IEquatable<CurrencyPair>
- Implements
- Inherited Members
- Extension Methods
Remarks
A pair is a strongly typed key intended for use in dictionaries and lookup tables. Compared to a raw tuple of codes, it centralises validation and makes the directional meaning of each currency obvious at the call site.
Constructors
CurrencyPair(CurrencyCode, CurrencyCode)
Initializes a new instance of the CurrencyPair struct.
public CurrencyPair(CurrencyCode from, CurrencyCode to)
Parameters
fromCurrencyCodeThe source currency.
toCurrencyCodeThe destination currency.
Exceptions
- ArgumentOutOfRangeException
Thrown if
fromortois None or is not a defined CurrencyCode member.
Properties
From
Gets the source currency.
public CurrencyCode From { get; }
Property Value
- CurrencyCode
The currency an amount is converted from.
IsValid
Gets a value indicating whether this instance carries two real currencies and can therefore be used safely as a directional key.
public bool IsValid { get; }
Property Value
Remarks
Because CurrencyPair is a value type, default(CurrencyPair) bypasses
the validating constructor and leaves both currencies None. Public boundaries that
accept an CurrencyPair should reject any instance whose IsValid property is
false.
To
Gets the destination currency.
public CurrencyCode To { get; }
Property Value
- CurrencyCode
The currency an amount is converted to.
Methods
Equals(CurrencyPair)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(CurrencyPair other)
Parameters
otherCurrencyPairAn object to compare with this object.
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Inverse()
public CurrencyPair Inverse()
Returns
- CurrencyPair
A new CurrencyPair describing the reverse-direction quotation.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
operator ==(CurrencyPair, CurrencyPair)
public static bool operator ==(CurrencyPair left, CurrencyPair right)
Parameters
leftCurrencyPairrightCurrencyPair
Returns
operator !=(CurrencyPair, CurrencyPair)
public static bool operator !=(CurrencyPair left, CurrencyPair right)
Parameters
leftCurrencyPairrightCurrencyPair
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |