@@ -36,7 +36,7 @@ public Money(int amount, Option<Currency> currency = default)
3636 public bool IsZero
3737 => Amount == 0m ;
3838
39- // These operators supports the operators on IMoneyExpression, because Money + Money or Money * factor does not work otherwise without a cast.
39+ // These operators support the operators on IMoneyExpression, because Money + Money or Money * factor does not work otherwise without a cast.
4040 public static IMoneyExpression operator + ( Money augend , IMoneyExpression addend )
4141 => augend . Add ( addend ) ;
4242
@@ -61,8 +61,8 @@ public bool IsZero
6161 public static decimal operator / ( Money dividend , IMoneyExpression divisor )
6262 => dividend . Divide ( divisor ) ;
6363
64- private static Currency SelectCurrency ( Option < Currency > currency )
65- => currency . GetOrElse ( CurrencyCulture . CurrentCurrency ) ;
64+ TState IMoneyExpression . Accept < TState > ( IMoneyExpressionVisitor < TState > visitor )
65+ => visitor . Visit ( this ) ;
6666
6767 public static Option < Money > ParseOrNone ( string money , Option < Currency > currency = default )
6868 => CurrencyCulture
@@ -72,6 +72,14 @@ public static Option<Money> ParseOrNone(string money, Option<Currency> currency
7272 some : ParseWithFormatProvider ( money ) )
7373 . AndThen ( amount => new Money ( amount , SelectCurrency ( currency ) ) ) ;
7474
75+ public override string ToString ( )
76+ => CurrencyCulture . FormatProviderFromCurrency ( Currency ) . Match (
77+ none : ( ) => string . Format ( $ "{{0:N{ Currency . MinorUnitDigits } }} {{1}}", Amount , Currency . AlphabeticCurrencyCode ) ,
78+ some : formatProvider => string . Format ( formatProvider , $ "{{0:C{ Currency . MinorUnitDigits } }}", Amount ) ) ;
79+
80+ private static Currency SelectCurrency ( Option < Currency > currency )
81+ => currency . GetOrElse ( CurrencyCulture . CurrentCurrency ) ;
82+
7583 private static Func < Option < decimal > > ParseManually ( string money )
7684 => ( )
7785 => RemoveIsoCurrency ( money ) . ParseDecimalOrNone ( ) ;
@@ -87,12 +95,4 @@ private static string RemoveIsoCurrency(string money)
8795 private static Func < IFormatProvider , Option < decimal > > ParseWithFormatProvider ( string money )
8896 => formatProvider
8997 => money . ParseDecimalOrNone ( NumberStyles . Currency , formatProvider ) ;
90-
91- public override string ToString ( )
92- => CurrencyCulture . FormatProviderFromCurrency ( Currency ) . Match (
93- none : ( ) => string . Format ( $ "{{0:N{ Currency . MinorUnitDigits } }} {{1}}", Amount , Currency . AlphabeticCurrencyCode ) ,
94- some : formatProvider => string . Format ( formatProvider , $ "{{0:C{ Currency . MinorUnitDigits } }}", Amount ) ) ;
95-
96- TState IMoneyExpression . Accept < TState > ( IMoneyExpressionVisitor < TState > visitor )
97- => visitor . Visit ( this ) ;
9898}
0 commit comments