Skip to content

Commit

Permalink
Merge pull request #26 from polyadic/use-polyadic-code-style
Browse files Browse the repository at this point in the history
Use Polyadic.CodeStyle and fix the prolems
  • Loading branch information
FreeApophis authored Jan 28, 2025
2 parents 0776f3d + 9243662 commit 0c96462
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Messerli.CodeStyle" PrivateAssets="all" />
<PackageReference Include="Polyadic.CodeStyle" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup Label="Deterministic Builds and Source Link">
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand Down
2 changes: 0 additions & 2 deletions Funcky.Money.SourceGenerator/XmlNodeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Xml;

namespace Funcky.Money.SourceGenerator;
Expand Down
6 changes: 2 additions & 4 deletions Funcky.Money.Test/MoneyTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections;
using System.Globalization;
using FsCheck;
using FsCheck.Xunit;
using Xunit;
Expand All @@ -8,9 +7,8 @@ namespace Funcky.Test;

public sealed class MoneyTest
{
public MoneyTest() =>
Arb
.Register<MoneyArbitraries>();
public MoneyTest()
=> Arb.Register<MoneyArbitraries>();

private static MoneyEvaluationContext SwissRounding
=> MoneyEvaluationContext
Expand Down
22 changes: 11 additions & 11 deletions Funcky.Money/Money.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Money(int amount, Option<Currency> currency = default)
public bool IsZero
=> Amount == 0m;

// These operators supports the operators on IMoneyExpression, because Money + Money or Money * factor does not work otherwise without a cast.
// These operators support the operators on IMoneyExpression, because Money + Money or Money * factor does not work otherwise without a cast.
public static IMoneyExpression operator +(Money augend, IMoneyExpression addend)
=> augend.Add(addend);

Expand All @@ -61,8 +61,8 @@ public bool IsZero
public static decimal operator /(Money dividend, IMoneyExpression divisor)
=> dividend.Divide(divisor);

private static Currency SelectCurrency(Option<Currency> currency)
=> currency.GetOrElse(CurrencyCulture.CurrentCurrency);
TState IMoneyExpression.Accept<TState>(IMoneyExpressionVisitor<TState> visitor)
=> visitor.Visit(this);

public static Option<Money> ParseOrNone(string money, Option<Currency> currency = default)
=> CurrencyCulture
Expand All @@ -72,6 +72,14 @@ public static Option<Money> ParseOrNone(string money, Option<Currency> currency
some: ParseWithFormatProvider(money))
.AndThen(amount => new Money(amount, SelectCurrency(currency)));

public override string ToString()
=> CurrencyCulture.FormatProviderFromCurrency(Currency).Match(
none: () => string.Format($"{{0:N{Currency.MinorUnitDigits}}} {{1}}", Amount, Currency.AlphabeticCurrencyCode),
some: formatProvider => string.Format(formatProvider, $"{{0:C{Currency.MinorUnitDigits}}}", Amount));

private static Currency SelectCurrency(Option<Currency> currency)
=> currency.GetOrElse(CurrencyCulture.CurrentCurrency);

private static Func<Option<decimal>> ParseManually(string money)
=> ()
=> RemoveIsoCurrency(money).ParseDecimalOrNone();
Expand All @@ -87,12 +95,4 @@ private static string RemoveIsoCurrency(string money)
private static Func<IFormatProvider, Option<decimal>> ParseWithFormatProvider(string money)
=> formatProvider
=> money.ParseDecimalOrNone(NumberStyles.Currency, formatProvider);

public override string ToString()
=> CurrencyCulture.FormatProviderFromCurrency(Currency).Match(
none: () => string.Format($"{{0:N{Currency.MinorUnitDigits}}} {{1}}", Amount, Currency.AlphabeticCurrencyCode),
some: formatProvider => string.Format(formatProvider, $"{{0:C{Currency.MinorUnitDigits}}}", Amount));

TState IMoneyExpression.Accept<TState>(IMoneyExpressionVisitor<TState> visitor)
=> visitor.Visit(this);
}
2 changes: 1 addition & 1 deletion Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ItemGroup>
<ItemGroup Label="Build Dependencies">
<PackageReference Update="Funcky.DiscriminatedUnion" Version="1.0.0" />
<PackageReference Update="Messerli.CodeStyle" Version="2.1.3 " />
<PackageReference Update="Polyadic.CodeStyle" Version="1.0.0" />
<PackageReference Update="IsExternalInit" Version="[1.0.3, 2.0.0)" />
<PackageReference Update="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
Expand Down

0 comments on commit 0c96462

Please sign in to comment.