Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Polyadic.CodeStyle and fix the problems #26

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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