2using System.Runtime.Serialization;
15 #region Private Properties
19 private int? _hashCode;
22 private string _currency;
23 private double _value;
24 private DateTime? _valueDate;
25 private double? _rate;
26 private string _rateCurrency;
27 #endregion Private Properties
32 [DataMember(Order = 2)]
46 [DataMember(Order = 3)]
60 [DataMember(Order = 4)]
75 [DataMember(Order = 5)]
76 [GreaterThan(0, canEqual: true)]
89 [DataMember(Order = 6)]
96 _rateCurrency =
value;
100 #endregion Properties
104 [Obsolete(
"Constructor only exists temporarily for the deserializer. All monetary units " +
105 "should be created using one of the other constructors.")]
146 #endregion Constructors
148 #region Object Overrides
158 double absValue = Math.Abs(
value);
159 string strRepresentation = 1E18 >= absValue && absValue >= 1000 ?
162 strRepresentation = $
"{currency} {strRepresentation}";
165 strRepresentation +=
" FX rate fixed to " +
value_date.Value.ToString(
"o");
167 strRepresentation += $
" FX rate fixed to {rate_currency} {_rate.Value:G}";
168 return strRepresentation;
175 Equals(_currency, other.currency) &&
176 Equals(_value, other.value) &&
177 Equals(_valueDate, other.value_date) &&
178 Equals(_rate, other.rate) &&
179 Equals(_rateCurrency, other.rate_currency);
184 public override bool Equals(
object obj) =>
191 if (!_hashCode.HasValue)
192 _hashCode =
new { _currency, _value, _valueDate, _rate, _rateCurrency }.GetHashCode();
193 return _hashCode.Value;
195 #endregion Object Overrides
Base class used by all types and resources.
Representation of a monetary value with a currency.
DateTime? value_date
The date for which to retrieve the exchange rate whenever using this monetary unit and a currency con...
string currency
3-letter currency code based on ISO 4217 (see: https://en.wikipedia.org/wiki/ISO_4217)
MonetaryUnit(double value, string currency)
Construct a new monetary unit.
double? rate
The fixed rate to use whenever using this monetary unit and a currency conversion is required....
MonetaryUnit()
Construct an empty monetary unit.
bool Equals(MonetaryUnit other)
Determine if this MonetaryUnit is equivalent to another.
double value
The value of the monetary unit.
override bool Equals(object obj)
Determine if this MonetaryUnit is equivalent to another object.
string rate_currency
3-letter currency code that indicates the currency that the 'rate' parameter is the rate for....
override string ToString()
String representation of this MonetaryUnit's currency and value, and of its fixed exchange rate prope...
override int GetHashCode()
Get the HashCode for this MonetaryUnit.
MonetaryUnit(double value, string currency, DateTime value_date)
Construct a new monetary unit with a preferred exchange rate conversion date.
MonetaryUnit(double value, string currency, double rate, string rate_currency)
Construct a new monetary unit with a fixed exchange rate conversion.