Skip to content

Commit

Permalink
Merge pull request #76 from dgg/feature/migrate-tools
Browse files Browse the repository at this point in the history
Feature/migrate tools
  • Loading branch information
dgg authored Jul 3, 2024
2 parents 1a02086 + be14b72 commit 419d3cf
Show file tree
Hide file tree
Showing 21 changed files with 1,904 additions and 506 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
uses: codecov/codecov-action@v3
with:
files: ./release/TestResults/coverage.cobertura.xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

- name: Upload Coveralls coverage
Expand Down
12 changes: 12 additions & 0 deletions src/NMoneys/Currency.Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Reflection;
using NMoneys.Support;

namespace NMoneys;
Expand Down Expand Up @@ -39,4 +40,15 @@ public static void Configure(ValueTuple<CurrencyIsoCode, CurrencyConfiguration>[
Configure(tuple.Item1, tuple.Item2);
}
}

/// <summary>
/// Returns the corresponding canonical culture assigned to the currency.
/// </summary>
/// <remarks>For internal verification purposes.</remarks>
/// <returns>The canonical culture or <c>null</c> is not decorated.</returns>
public CanonicalCultureAttribute? GetCanonicalCulture()
{
CanonicalCultureAttribute? attribute = IsoCode.FieldOf().GetCustomAttribute<CanonicalCultureAttribute>();
return attribute;
}
}
39 changes: 39 additions & 0 deletions src/NMoneys/CurrencyConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Globalization;

namespace NMoneys;

/// <summary>
Expand Down Expand Up @@ -52,4 +54,41 @@ public record CurrencyConfiguration()
/// Override <see cref="Currency.Entity"/>.
/// </summary>
public ValueTuple<ushort?, string?> Reference { get; init; } = (null, null);

/// <summary>
/// Creates a <see cref="Currency"/> configuration override with the data of the provided <paramref name="culture"/>
/// and its corresponding <see cref="RegionInfo"/>.
/// </summary>
/// <param name="culture">Instance with the overriding information (<see cref="CultureInfo.NumberFormat"/> "currency" properties).</param>
/// <param name="isObsolete">Whether the corresponding override is considered obsolete (<c>false</c> by default).</param>
/// <returns>An instance with the overriding data.</returns>
public static CurrencyConfiguration From(CultureInfo culture, bool isObsolete = false) =>
From(culture, new RegionInfo(culture.Name), isObsolete);

/// <summary>
/// Creates a <see cref="Currency"/> configuration override with the data of the provided <paramref name="culture"/>
/// and <paramref name="region"/>.
/// </summary>
/// <param name="culture">Instance with the overriding information (<see cref="CultureInfo.NumberFormat"/> "currency" properties).</param>
/// <param name="region">Instance with the overriding information (currency English and native names).</param>
/// <param name="isObsolete">Whether the corresponding override is considered obsolete (<c>false</c> by default).</param>
/// <returns>An instance with the overriding data.</returns>
public static CurrencyConfiguration From(CultureInfo culture, RegionInfo region, bool isObsolete = false)
{
NumberFormatInfo nf = culture.NumberFormat;
CurrencyConfiguration configuration = new()
{
NativeName = region.CurrencyNativeName,
EnglishName = region.CurrencyEnglishName,
Symbol = nf.CurrencySymbol,
SignificantDecimalDigits = (byte)nf.CurrencyDecimalDigits,
DecimalSeparator = nf.CurrencyDecimalSeparator,
GroupSeparator = nf.CurrencyGroupSeparator,
GroupSizes = nf.CurrencyGroupSizes.Select(s => (byte)s).ToArray(),
PositivePattern = (byte)nf.CurrencyPositivePattern,
NegativePattern = (byte)nf.CurrencyNegativePattern,
IsObsolete = isObsolete
};
return configuration;
}
}
Loading

0 comments on commit 419d3cf

Please sign in to comment.