MoneyOfTCurrencyExtensions Class
Definition
Provides sign, magnitude, and comparison convenience members for the strongly-typed Money<TCurrency> type, keeping those derived helpers off the core value type while preserving familiar property-style access.
public static class MoneyOfTCurrencyExtensions
- Inheritance
-
MoneyOfTCurrencyExtensions
- Inherited Members
Remarks
Each instance member is a thin projection over Amount and the public arithmetic
surface, carrying no state of its own; the Min, Max, and Clamp helpers are static because they
compare two or more operands. Splitting them into this extension surface keeps Money<TCurrency>
focused on construction, arithmetic, equality, and formatting.
When compiled with a tool-chain that supports C# 14 extension members the instance helpers are exposed as extension
properties (for example money.IsZero); otherwise they compile as classic extension methods (for example
money.IsZero()).
Methods
Abs<TCurrency>(Money<TCurrency>)
Returns the absolute value of the specified instance.
public static Money<TCurrency> Abs<TCurrency>(this Money<TCurrency> value) where TCurrency : ICurrency
Parameters
valueMoney<TCurrency>The monetary value whose magnitude is taken.
Returns
- Money<TCurrency>
A Money<TCurrency> whose amount is
|Amount|.
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
Clamp<TCurrency>(Money<TCurrency>, Money<TCurrency>, Money<TCurrency>)
Clamps value to the inclusive range [min, max].
public static Money<TCurrency> Clamp<TCurrency>(Money<TCurrency> value, Money<TCurrency> min, Money<TCurrency> max) where TCurrency : ICurrency
Parameters
valueMoney<TCurrency>The value to clamp.
minMoney<TCurrency>The lower bound (inclusive).
maxMoney<TCurrency>The upper bound (inclusive).
Returns
- Money<TCurrency>
valuewhen it lies within the range, otherwise the nearer bound.
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
Exceptions
- ArgumentException
minis greater thanmax.
IsNegative<TCurrency>(Money<TCurrency>)
Returns a value indicating whether the specified instance is strictly less than zero.
public static bool IsNegative<TCurrency>(this Money<TCurrency> value) where TCurrency : ICurrency
Parameters
valueMoney<TCurrency>The monetary value to test.
Returns
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
IsPositive<TCurrency>(Money<TCurrency>)
Returns a value indicating whether the specified instance is strictly greater than zero.
public static bool IsPositive<TCurrency>(this Money<TCurrency> value) where TCurrency : ICurrency
Parameters
valueMoney<TCurrency>The monetary value to test.
Returns
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
IsZero<TCurrency>(Money<TCurrency>)
Returns a value indicating whether the specified instance represents zero.
public static bool IsZero<TCurrency>(this Money<TCurrency> value) where TCurrency : ICurrency
Parameters
valueMoney<TCurrency>The monetary value to test.
Returns
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
Max<TCurrency>(Money<TCurrency>, Money<TCurrency>)
Returns the larger of two monetary values in the same currency.
public static Money<TCurrency> Max<TCurrency>(Money<TCurrency> left, Money<TCurrency> right) where TCurrency : ICurrency
Parameters
Returns
- Money<TCurrency>
The greater of
leftandright.
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
Min<TCurrency>(Money<TCurrency>, Money<TCurrency>)
Returns the smaller of two monetary values in the same currency.
public static Money<TCurrency> Min<TCurrency>(Money<TCurrency> left, Money<TCurrency> right) where TCurrency : ICurrency
Parameters
Returns
- Money<TCurrency>
The lesser of
leftandright.
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
Sign<TCurrency>(Money<TCurrency>)
Returns the sign of the specified instance.
public static int Sign<TCurrency>(this Money<TCurrency> value) where TCurrency : ICurrency
Parameters
valueMoney<TCurrency>The monetary value to test.
Returns
- int
-1when the amount is negative,0when the amount is zero, and1when the amount is positive.
Type Parameters
TCurrencyThe currency tag identifying the monetary type.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |