Class Currency
- Namespace
- Dynamicweb.Ecommerce.International
- Assembly
- Dynamicweb.Ecommerce.dll
Represents a currency used in the e-commerce system, including its code, symbol, rate, formatting, and translation support.
[Serializable]
public class Currency : ICloneable
- Inheritance
-
Currency
- Implements
- Inherited Members
Examples
var currency = new Currency
{
Code = "USD",
Symbol = "$",
Rate = 1.0,
IsDefault = true,
CultureInfo = "en-US"
};
currency.SetName("en", "US Dollar");
Remarks
The Currency class encapsulates all relevant information about a currency, such as its ISO code, symbol, exchange rate, formatting patterns, and culture information. It also supports translation of the currency name for multilingual scenarios and provides deep cloning functionality. The class implements ICloneable for cloning and Dynamicweb.Ecommerce.International.ITranslatable<T> for translation management.
Constructors
Currency()
Creates a new instance of Currency.
public Currency()
Remarks
Initializes the Translations collection with a factory that produces CurrencyTranslation items keyed by language identifier.
Properties
Code
Gets or sets the currency code.
public required string Code { get; set; }
Property Value
- string
The ISO 4217 alphabetic currency code (e.g.,
USD,EUR,DKK).
CultureInfo
Gets or sets the culture information.
public string? CultureInfo { get; set; }
Property Value
- string
A .NET culture name (e.g.,
en-US,da-DK) used for currency/number formatting. If not set or invalid, GetCultureInfo() falls back to CurrentCulture.
IsDefault
Gets or sets the value indicating whether the currency is default.
public bool IsDefault { get; set; }
Property Value
NegativePattern
Gets or sets the negative pattern for this Currency. Only used if CultureInfo is used. http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencynegativepattern(v=vs.110).aspx
public int NegativePattern { get; set; }
Property Value
Remarks
Set to -1 to use the pattern from the resolved CultureInfo.
PayGatewayCode
Gets or sets the code of pay gateway.
public int PayGatewayCode { get; set; }
Property Value
- int
An implementation-specific identifier of the payment gateway associated with this currency, if any.
PositivePattern
Gets or sets the positive pattern for this Currency. Only used if CultureInfo is used. http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencypositivepattern(v=vs.110).aspx
public int PositivePattern { get; set; }
Property Value
Remarks
Set to -1 to use the pattern from the resolved CultureInfo.
Rate
Gets or sets the rate.
public double Rate { get; set; }
Property Value
- double
The exchange rate relative to the system's base currency. The interpretation of this value depends on the surrounding pricing context and configuration.
Rounding
Gets or sets the Rounding.
public Rounding? Rounding { get; set; }
Property Value
Remarks
When getting, resolves the Rounding from RoundingId using Services.Roundings.
When setting, updates RoundingId from the provided rounding instance.
RoundingId
Gets or sets the rounding id.
public string? RoundingId { get; set; }
Property Value
Symbol
Gets or sets the symbol.
public string? Symbol { get; set; }
Property Value
- string
The localized currency symbol (e.g.,
$,€,kr). When UseCurrencyCodeForFormat is true, the Code can be used instead of the symbol when formatting prices.
Translations
Gets the translations
public TranslationCollection<CurrencyTranslation> Translations { get; }
Property Value
- TranslationCollection<CurrencyTranslation>
A collection of localized CurrencyTranslation entries keyed by language.
UseCurrencyCodeForFormat
Gets or sets a value indicating whether to use currency code for formatting prices instead of symbol,
i.e. EUR 1000 instead of € 1000.
public bool UseCurrencyCodeForFormat { get; set; }
Property Value
- bool
trueif currency code should be used for price formatting; otherwise,false.
Methods
Clone()
Creates a new instance of a class with the same value as an existing instance.
public object Clone()
Returns
- object
A deep clone of the current Currency instance, including a deep copy of Translations.
Remarks
Method performs a deep copy of all properties except the IsReadOnly property. IsReadOnly property always is set to False.
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
Remarks
Two Currency instances are considered equal if their Code values are equal using case-insensitive ordinal comparison.
GetCultureInfo()
Gets the CultureInfo related to the regional settings set on the currency.
public CultureInfo GetCultureInfo()
Returns
- CultureInfo
The CultureInfo related to the regional settings set on the currency. If none is specified or the configured culture is invalid, it will use the culture of the current context (CurrentCulture).
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
GetName(string)
Gets the name of the currency for the given language.
public string GetName(string languageId)
Parameters
languageIdstringThe language identifier (e.g.,
en,da) to resolve the translated currency name.
Returns
- string
The localized currency name if available for the specified language (or default language fallback); otherwise, returns the Code.
GetName(string, LanguageService)
Gets the name of the currency for the given language.
public string GetName(string languageId, LanguageService languageService)
Parameters
languageIdstringThe language identifier requested for the currency name.
languageServiceLanguageServiceThe language service used to determine the default language fallback.
Returns
- string
The localized currency name if available for the specified language (or default language fallback); otherwise, returns the Code.
Exceptions
- ArgumentNullException
Thrown when
languageServiceis null.
SetName(string, string)
Sets the name of the currency for the given language.
public void SetName(string languageId, string name)
Parameters
languageIdstringThe language identifier to set the translation for.
namestringThe localized currency name.
Remarks
Creates a new CurrencyTranslation if one does not already exist for the specified language.