Class SortedMoneyBag
Represents a bag of monetary values in one or more currencies sorted by currency code.
Implements
Namespace: Singulink.Globalization
Assembly: Singulink.Globalization.Currency.dll
Syntax
public sealed class SortedMoneyBag : IMoneyBag, ICollection<MonetaryValue>, IReadOnlyMoneyBag, IReadOnlyCollection<MonetaryValue>, IEnumerable<MonetaryValue>, IEnumerable, IFormattable
Remarks
Money bags have one value for each currency they contain, and values are ordered by their currency. If a value is added (or subtracted) in a currency that the bag already contains, the value is added to (or subtracted from) the existing value.
Money bags never contain any default MonetaryValue values (i.e. zero amount values that are not associated with any currency). Default values are ignored when being added to or subtracted from a bag.
Constructors
Name | Description |
---|---|
SortedMoneyBag() | Initializes a new instance of the SortedMoneyBag class with the Default currency registry. |
SortedMoneyBag(CurrencyRegistry) | Initializes a new instance of the SortedMoneyBag class with the specified currency registry. |
SortedMoneyBag(CurrencyRegistry, params MonetaryValue[]) | Initializes a new instance of the MoneyBag class with the specified currency registry and adds all the specified values. |
SortedMoneyBag(CurrencyRegistry, IEnumerable<MonetaryValue>) | Initializes a new instance of the MoneyBag class with the specified currency registry and adds all the specified values. |
SortedMoneyBag(CurrencyRegistry, ReadOnlySpan<MonetaryValue>) | Initializes a new instance of the SortedMoneyBag class with the specified currency registry and adds all the specified values. |
SortedMoneyBag(params MonetaryValue[]) | Initializes a new instance of the MoneyBag class with the Default currency registry and adds all the specified values. |
SortedMoneyBag(IEnumerable<MonetaryValue>) | Initializes a new instance of the MoneyBag class with the Default currency registry and adds all the specified values. |
SortedMoneyBag(ReadOnlySpan<MonetaryValue>) | Initializes a new instance of the SortedMoneyBag class with the Default currency registry and adds all the specified values. |
Properties
Name | Description |
---|---|
Count | Gets the number of values/currencies in this bag. |
Currencies | Gets the currencies that this bag contains. |
this[Currency] | Gets the value this bag contains of the specified currency. Returns the default monetary value if it does not contain the currency. |
this[string] | Gets the value this bag contains with the specified currency code. Returns the default monetary value if it does not contain the currency. |
Registry | Gets the currency registry associated with this bag. |
Methods
Name | Description |
---|---|
Add(MonetaryValue) | Adds the specified value to this bag. |
Add(decimal, Currency) | Adds the specified currency and amount to this bag. |
Add(decimal, string) | Adds the specified currency and amount to this bag. |
AddRange(IEnumerable<MonetaryValue>) | Adds the specified values to this bag. |
Clear() | Removes all values from this bag. |
Contains(MonetaryValue) | Determines whether this bag contains the specified value. |
Contains(decimal, Currency) | Determines whether this bag contains the specified amount and currency. |
Contains(decimal, string) | Determines whether this bag contains the specified amount and currency code. |
ContainsCurrency(Currency) | Determines whether this bag contains a value with the specified currency. |
ContainsCurrency(string) | Determines whether this bag contains a value with the specified currency code. |
GetEnumerator() | Returns an enumerator that iterates through the values in this bag. |
Remove(Currency) | Removes the value with the given currency. |
Remove(string) | Removes the value with the given currency code. |
RemoveAll(IEnumerable<Currency>) | Removes all the values from this bag that match the specified currencies. |
RemoveAll(Func<MonetaryValue, bool>) | Removes all the values from this bag that match the specified predicate and returns the resulting bag. |
RoundToCurrencyDigits() | Rounds each value's amount to its currency's DecimalDigits using ToEven midpoint rounding (i.e. "banker's rounding"). |
RoundToCurrencyDigits(MidpointRounding) | Rounds each value's amount to its currency's DecimalDigits using the specified midpoint rounding mode. |
SetAmount(decimal, Currency) | Sets the amount the bag contains for the specified currency code. |
SetAmount(decimal, string) | Sets the amount the bag contains for the specified currency code. |
SetValue(MonetaryValue) | Sets the value this bag contains for the currency of the specified value. |
Subtract(MonetaryValue) | Subtracts the specified value from this bag. Zero amounts are not trimmed from the bag. |
Subtract(decimal, Currency) | Adds the specified currency and amount to this bag. |
Subtract(decimal, string) | Subtracts the specified currency and amount from this bag. Zero amounts are not trimmed from the bag. |
SubtractRange(IEnumerable<MonetaryValue>) | Subtracts the specified values from this bag. Zero amounts are not trimmed from the bag. |
ToImmutableSet() | Copies the values in this bag to a new immutable bag that uses the same registry as this bag. |
ToString() | Returns a string representation of the monetary values this bag contains. |
ToString(string?, IFormatProvider?) | Returns a string representation of the monetary values this bag contains. |
TransformAmounts(Func<decimal, decimal>) | Applies the specified transformation to each value's amount in this bag. |
TransformAmounts(Func<decimal, decimal?>) | Applies the specified transformation to each value's amount in this bag. Amounts transformed to a null amount are removed. |
TransformValues(Func<MonetaryValue, decimal>) | Applies the specified transformation to each value's amount in this bag. |
TransformValues(Func<MonetaryValue, decimal?>) | Applies the specified transformation to each value's amount in this bag. Values transformed to a null amount are removed. |
TrimZeroAmounts() | Removes all zero amounts from this bag. |
TryGetAmount(Currency, out decimal) | Gets the amount associated with the specified currency. |
TryGetAmount(string, out decimal) | Gets the amount associated with the specified currency code. |
TryGetValue(Currency, out MonetaryValue) | Gets the monetary value associated with the specified currency. |
TryGetValue(string, out MonetaryValue) | Gets the monetary value associated with the specified currency code. |
Explicit Interface Implementations
Name | Description |
---|---|
IMoneyBag.Create(CurrencyRegistry, IEnumerable<MonetaryValue>) | Creates a bag that uses the specified currency registry and adds all the specified values. |
IReadOnlyMoneyBag.Create(CurrencyRegistry, IEnumerable<MonetaryValue>) | Creates a bag that uses the specified currency registry and adds all the specified values. |
IReadOnlyMoneyBag.Currencies | Gets the currencies that this bag contains. |
IReadOnlyMoneyBag.IsSorted | Gets a value indicating whether this bag is sorted by each value's currency code. |
ICollection<MonetaryValue>.CopyTo(MonetaryValue[], int) | Copies the elements of the ICollection<T> to an Array, starting at a particular Array index. |
ICollection<MonetaryValue>.IsReadOnly | Gets a value indicating whether the ICollection<T> is read-only. |
ICollection<MonetaryValue>.Remove(MonetaryValue) | Removes the first occurrence of a specific object from the ICollection<T>. |
IEnumerable<MonetaryValue>.GetEnumerator() | Returns an enumerator that iterates through the collection. |
IEnumerable.GetEnumerator() | Returns an enumerator that iterates through a collection. |