Class ImmutableMoneyBag
Represents an immutable bag of monetary values in one or more currencies.
Implements
Namespace: Singulink.Globalization
Assembly: Singulink.Globalization.Currency.dll
Syntax
public sealed class ImmutableMoneyBag : IImmutableMoneyBag, 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.
Properties
Name | Description |
---|---|
Count | Gets the number of values 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 and returns the resulting bag. |
Add(decimal, Currency) | Adds the specified currency and amount to this bag and returns the resulting bag. |
Add(decimal, string) | Adds the specified currency and amount to this bag and returns the resulting bag. |
AddRange(IEnumerable<MonetaryValue>) | Adds the specified values to this bag and returns the resulting bag. |
Clear() | Returns an empty immutable bag that has the same currency registry as 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. |
Create() | Creates an empty immutable money bag that uses the Default currency registry. |
Create(CurrencyRegistry) | Creates an empty immutable money bag that uses the specified currency registry. |
Create(CurrencyRegistry, MonetaryValue) | Creates an immutable money bag that uses the specified currency registry and contains the specified value. |
Create(CurrencyRegistry, params MonetaryValue[]) | Creates an immutable money bag that uses the specified currency registry and adds all the specified values. |
Create(CurrencyRegistry, ReadOnlySpan<MonetaryValue>) | Creates an immutable money bag that uses the specified currency registry and adds all the specified values. |
Create(MonetaryValue) | Creates an empty immutable money bag that uses the Default currency registry and contains the specified value. |
Create(params MonetaryValue[]) | Creates an immutable money bag that uses the Default currency registry and adds all the specified values. |
Create(ReadOnlySpan<MonetaryValue>) | Creates an immutable money bag that uses the Default currency registry and adds all the specified values. |
CreateRange(CurrencyRegistry, IEnumerable<MonetaryValue>) | Creates an immutable money bag that uses the specified currency registry and adds all the specified values. |
CreateRange(IEnumerable<MonetaryValue>) | Creates an immutable money bag that uses the Default currency registry and adds all the specified values. |
GetEnumerator() | Returns an enumerator that iterates through the values in this bag. |
Remove(Currency) | Removes the value with the given currency and returns the resulting bag. |
Remove(string) | Removes the value with the given currency code and returns the resulting bag. |
RemoveAll(IEnumerable<Currency>) | Removes all the values from this bag that match the specified currencies and returns the resulting bag. |
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") and returns the resulting bag. |
RoundToCurrencyDigits(MidpointRounding) | Rounds each value's amount to its currency's DecimalDigits using the specified midpoint rounding mode and returns the resulting bag. |
SetAmount(decimal, Currency) | Sets the amount the bag contains for the specified currency code and returns the resulting bag. |
SetAmount(decimal, string) | Sets the amount the bag contains for the specified currency code and returns the resulting bag. |
SetValue(MonetaryValue) | Sets the value this bag contains for the currency of the specified value and returns the resulting bag. |
Subtract(MonetaryValue) | Subtracts the specified value from this bag and returns the resulting bag. Zero amounts are not trimmed from the bag. |
Subtract(decimal, Currency) | Adds the specified currency and amount to this bag and returns the resulting bag. |
Subtract(decimal, string) | Subtracts the specified currency and amount from this bag and returns the resulting bag. |
SubtractRange(IEnumerable<MonetaryValue>) | Subtracts the specified values from this bag and returns the resulting bag. Zero amounts are not trimmed from the 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 and returns the resulting bag. |
TransformAmounts(Func<decimal, decimal?>) | Applies the specified transformation to each value's amount in this bag and returns the resulting 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 and returns the resulting bag. |
TransformValues(Func<MonetaryValue, decimal?>) | Applies the specified transformation to each value's amount in this bag and returns the resulting bag. Values transformed to a null amount are removed. |
TrimZeroAmounts() | Removes all zero amounts from this bag and returns the resulting 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 |
---|---|
IImmutableMoneyBag.Add(MonetaryValue) | Adds the specified value to this bag and returns the resulting bag. |
IImmutableMoneyBag.Add(decimal, Currency) | Adds the specified currency and amount to this bag and returns the resulting bag. |
IImmutableMoneyBag.Add(decimal, string) | Adds the specified currency and amount to this bag and returns the resulting bag. |
IImmutableMoneyBag.AddRange(IEnumerable<MonetaryValue>) | Adds the specified values to this bag and returns the resulting bag. |
IImmutableMoneyBag.Clear() | Returns an empty immutable bag that has the same currency registry as this bag. |
IImmutableMoneyBag.Create(CurrencyRegistry, IEnumerable<MonetaryValue>) | Creates a bag that uses the specified currency registry and adds all the specified values. |
IImmutableMoneyBag.Remove(Currency) | Removes the value with the given currency and returns the resulting bag. |
IImmutableMoneyBag.Remove(string) | Removes the value with the given currency code and returns the resulting bag. |
IImmutableMoneyBag.RemoveAll(IEnumerable<Currency>) | Removes all the values from this bag that match the specified currencies and returns the resulting bag. |
IImmutableMoneyBag.RemoveAll(Func<MonetaryValue, bool>) | Removes all the values from this bag that match the specified predicate and returns the resulting bag. |
IImmutableMoneyBag.RoundToCurrencyDigits() | Rounds each value's amount to its currency's DecimalDigits using ToEven midpoint rounding (i.e. "banker's rounding") and returns the resulting bag. |
IImmutableMoneyBag.RoundToCurrencyDigits(MidpointRounding) | Rounds each value's amount to its currency's DecimalDigits using the specified midpoint rounding mode and returns the resulting bag. |
IImmutableMoneyBag.SetAmount(decimal, Currency) | Sets the amount the bag contains for the specified currency code and returns the resulting bag. |
IImmutableMoneyBag.SetAmount(decimal, string) | Sets the amount the bag contains for the specified currency code and returns the resulting bag. |
IImmutableMoneyBag.SetValue(MonetaryValue) | Sets the value this bag contains for the currency of the specified value and returns the resulting bag. |
IImmutableMoneyBag.Subtract(MonetaryValue) | Subtracts the specified value from this bag and returns the resulting bag. Zero amounts are not trimmed from the bag. |
IImmutableMoneyBag.Subtract(decimal, Currency) | Adds the specified currency and amount to this bag and returns the resulting bag. |
IImmutableMoneyBag.Subtract(decimal, string) | Subtracts the specified currency and amount from this bag and returns the resulting bag. |
IImmutableMoneyBag.SubtractRange(IEnumerable<MonetaryValue>) | Subtracts the specified values from this bag and returns the resulting bag. Zero amounts are not trimmed from the bag. |
IImmutableMoneyBag.TransformAmounts(Func<decimal, decimal>) | Applies the specified transformation to each value's amount in this bag and returns the resulting bag. |
IImmutableMoneyBag.TransformAmounts(Func<decimal, decimal?>) | Applies the specified transformation to each value's amount in this bag and returns the resulting bag. Amounts transformed to a null amount are removed. |
IImmutableMoneyBag.TransformValues(Func<MonetaryValue, decimal>) | Applies the specified transformation to each value's amount in this bag and returns the resulting bag. |
IImmutableMoneyBag.TransformValues(Func<MonetaryValue, decimal?>) | Applies the specified transformation to each value's amount in this bag and returns the resulting bag. Values transformed to a null amount are removed. |
IImmutableMoneyBag.TrimZeroAmounts() | Removes all zero amounts from this bag and returns the resulting bag. |
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>.Add(MonetaryValue) | Not supported. |
ICollection<MonetaryValue>.Clear() | Not supported. |
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 bag is read-only. Always returns true. |
ICollection<MonetaryValue>.Remove(MonetaryValue) | Not supported. |
IEnumerable<MonetaryValue>.GetEnumerator() | Returns an enumerator that iterates through the collection. |
IEnumerable.GetEnumerator() | Returns an enumerator that iterates through a collection. |