Skip to content

Commit 0c96462

Browse files
authored
Merge pull request #26 from polyadic/use-polyadic-code-style
Use Polyadic.CodeStyle and fix the prolems
2 parents 0776f3d + 9243662 commit 0c96462

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1717
</PropertyGroup>
1818
<ItemGroup>
19-
<PackageReference Include="Messerli.CodeStyle" PrivateAssets="all" />
19+
<PackageReference Include="Polyadic.CodeStyle" PrivateAssets="all" />
2020
</ItemGroup>
2121
<PropertyGroup Label="Deterministic Builds and Source Link">
2222
<PublishRepositoryUrl>true</PublishRepositoryUrl>

Funcky.Money.SourceGenerator/XmlNodeExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections.Generic;
21
using System.Collections.Immutable;
3-
using System.Linq;
42
using System.Xml;
53

64
namespace Funcky.Money.SourceGenerator;

Funcky.Money.Test/MoneyTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections;
2-
using System.Globalization;
32
using FsCheck;
43
using FsCheck.Xunit;
54
using Xunit;
@@ -8,9 +7,8 @@ namespace Funcky.Test;
87

98
public sealed class MoneyTest
109
{
11-
public MoneyTest() =>
12-
Arb
13-
.Register<MoneyArbitraries>();
10+
public MoneyTest()
11+
=> Arb.Register<MoneyArbitraries>();
1412

1513
private static MoneyEvaluationContext SwissRounding
1614
=> MoneyEvaluationContext

Funcky.Money/Money.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</ItemGroup>
66
<ItemGroup Label="Build Dependencies">
77
<PackageReference Update="Funcky.DiscriminatedUnion" Version="1.0.0" />
8-
<PackageReference Update="Messerli.CodeStyle" Version="2.1.3 " />
8+
<PackageReference Update="Polyadic.CodeStyle" Version="1.0.0" />
99
<PackageReference Update="IsExternalInit" Version="[1.0.3, 2.0.0)" />
1010
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
1111
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />

0 commit comments

Comments
 (0)