Table of Contents

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

from CurrencyCode

The source currency.

to CurrencyCode

The destination currency.

Exceptions

ArgumentOutOfRangeException

Thrown if from or to is 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

bool

true when both From and To are not None; otherwise false.

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

other CurrencyPair

An object to compare with this object.

Returns

bool

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

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

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()

Returns the inverse pair with From and To swapped.

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

left CurrencyPair
right CurrencyPair

Returns

bool

operator !=(CurrencyPair, CurrencyPair)

public static bool operator !=(CurrencyPair left, CurrencyPair right)

Parameters

left CurrencyPair
right CurrencyPair

Returns

bool

Applies to

ProductVersions
.NET8, 10