Skip to content

Commit

Permalink
move tools to polyglot books
Browse files Browse the repository at this point in the history
  • Loading branch information
dgg committed Jun 5, 2024
1 parent e4e3805 commit 3bd2a05
Show file tree
Hide file tree
Showing 10 changed files with 1,073 additions and 38 deletions.
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;
}
}
8 changes: 4 additions & 4 deletions src/NMoneys/NMoneys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
</PropertyGroup>

<PropertyGroup>
<Version>7.1.0</Version>
<AssemblyVersion>7.1.0.0</AssemblyVersion>
<FileVersion>7.1.0.0</FileVersion>
<PackageVersion>7.1.0</PackageVersion>
<Version>7.1.1</Version>
<AssemblyVersion>7.1.1.0</AssemblyVersion>
<FileVersion>7.1.1.0</FileVersion>
<PackageVersion>7.1.1</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/NMoneys/Support/CanonicalCultureAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ namespace NMoneys.Support;
/// </summary>
/// <remarks>For internal verification purposes, it does not have any effect on currency runtime.</remarks>
[AttributeUsage(AttributeTargets.Field)]
internal sealed class CanonicalCultureAttribute : Attribute
public sealed class CanonicalCultureAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="CanonicalCultureAttribute"/> class.
/// </summary>
/// <param name="cultureName">Name of the corresponding <see cref="CultureInfo"/> instance.</param>
public CanonicalCultureAttribute(string cultureName)
{
CultureName = cultureName;
Expand Down
19 changes: 0 additions & 19 deletions tools/Print-Info.ps1

This file was deleted.

14 changes: 0 additions & 14 deletions tools/Read-CI-Property.ps1

This file was deleted.

182 changes: 182 additions & 0 deletions tools/compare_canonicals.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
},
"vscode": {
"languageId": "polyglot-notebook"
}
},
"outputs": [],
"source": [
"#r \"../src/NMoneys/bin/Debug/net6.0/NMoneys.dll\"\n",
"\n",
"using NMoneys;\n",
"using NMoneys.Support;\n",
"using System.Numerics;\n",
"using System.Reflection;\n",
"using System.Globalization;\n",
"\n",
"record Diff(string Name, string FromCurrency, string FromGlobalization)\n",
"{\n",
"\tprivate static string str<T>(T i) where T : IBinaryInteger<T> \n",
"\t{\n",
"\t\treturn i.ToString(\"D\", CultureInfo.InvariantCulture);\n",
"\t}\n",
"\tprivate static string str<T>(T[] i) where T : IBinaryInteger<T> \n",
"\t{\n",
"\t\treturn string.Join('|', i);\n",
"\t}\n",
"\n",
"\tpublic static Diff[] Build(Currency currency)\n",
"\t{\n",
"\t\tCanonicalCultureAttribute attr = currency.GetCanonicalCulture();\n",
"\t\tif (attr is null) return Array.Empty<Diff>();\n",
"\n",
"\t\tCultureInfo ci = attr.Culture();\n",
"\t\tNumberFormatInfo nfi = ci.NumberFormat;\n",
"\t\tvar ri = new RegionInfo(ci.Name);\n",
"\t\tStringComparer ordinal = StringComparer.Ordinal;\n",
"\t\tStringComparer native = StringComparer.Create(ci, false);\n",
"\n",
"\t\tList<Diff> diffs = new List<Diff>(10);\n",
"\t\tif (currency.IsoCode != Currency.Code.Parse(ri.ISOCurrencySymbol))\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"ri.ISOCurrencySymbol\", currency.AlphabeticCode, ri.ISOCurrencySymbol));\n",
"\t\t}\n",
"\t\tif (!ordinal.Equals(currency.EnglishName, ri.CurrencyEnglishName))\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"ri.CurrencyEnglishName\", currency.EnglishName, ri.CurrencyEnglishName));\n",
"\t\t}\n",
"\t\tif (!native.Equals(currency.NativeName, ri.CurrencyNativeName))\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"ri.CurrencyNativeName\", currency.NativeName, ri.CurrencyNativeName));\n",
"\t\t}\n",
"\t\tif (!native.Equals(currency.Symbol, ri.CurrencySymbol))\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"ri.CurrencySymbol\", currency.Symbol, ri.CurrencySymbol));\n",
"\t\t}\n",
"\t\tif (currency.SignificantDecimalDigits != nfi.CurrencyDecimalDigits)\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"nfi.CurrencyDecimalDigits\", str(currency.SignificantDecimalDigits), str(nfi.CurrencyDecimalDigits)));\n",
"\t\t}\n",
"\t\tif (!ordinal.Equals(currency.DecimalSeparator, nfi.CurrencyDecimalSeparator))\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"nfi.CurrencyDecimalSeparator\", currency.DecimalSeparator, nfi.CurrencyDecimalSeparator));\n",
"\t\t}\n",
"\t\tif (!ordinal.Equals(currency.GroupSeparator, nfi.CurrencyGroupSeparator))\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"nfi.CurrencyGroupSeparator\", currency.GroupSeparator, nfi.CurrencyGroupSeparator));\n",
"\t\t}\n",
"\t\tif (!currency.GroupSizes.SequenceEqual(nfi.CurrencyGroupSizes.Select(s => (byte)s)))\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"nfi.CurrencyGroupSizes\", str(currency.GroupSizes), str(nfi.CurrencyGroupSizes)));\n",
"\t\t}\n",
"\t\tif (currency.PositivePattern != nfi.CurrencyPositivePattern)\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"nfi.CurrencyPositivePattern\", str(currency.PositivePattern), str(nfi.CurrencyPositivePattern)));\n",
"\t\t}\n",
"\t\tif (currency.NegativePattern != nfi.CurrencyNegativePattern)\n",
"\t\t{\n",
"\t\t\tdiffs.Add(new Diff(\"nfi.CurrencyNegativePattern\", str(currency.NegativePattern), str(nfi.CurrencyNegativePattern)));\n",
"\t\t}\n",
"\n",
"\t\treturn diffs.ToArray();\n",
"\t}\n",
"};"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
},
"vscode": {
"languageId": "polyglot-notebook"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"dni-plaintext\"><pre>[ 4, 4, 3, 5, 4, 3, 2, 1, 1, 5, 3, 1, 1, 5, 3, 1, 2, 2, 2, 4 ... (more) ]</pre></div><style>\r\n",
".dni-code-hint {\r\n",
" font-style: italic;\r\n",
" overflow: hidden;\r\n",
" white-space: nowrap;\r\n",
"}\r\n",
".dni-treeview {\r\n",
" white-space: nowrap;\r\n",
"}\r\n",
".dni-treeview td {\r\n",
" vertical-align: top;\r\n",
" text-align: start;\r\n",
"}\r\n",
"details.dni-treeview {\r\n",
" padding-left: 1em;\r\n",
"}\r\n",
"table td {\r\n",
" text-align: start;\r\n",
"}\r\n",
"table tr { \r\n",
" vertical-align: top; \r\n",
" margin: 0em 0px;\r\n",
"}\r\n",
"table tr td pre \r\n",
"{ \r\n",
" vertical-align: top !important; \r\n",
" margin: 0em 0px !important;\r\n",
"} \r\n",
"table th {\r\n",
" text-align: start;\r\n",
"}\r\n",
"</style>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Currency.FindAll()\n",
"\t.Select(c => new { Currency = c, Diffs = Diff.Build(c) })\n",
"\t.Where(a => a.Diffs.Length > 0)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"name": "csharp"
},
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [],
"name": "csharp"
}
]
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 3bd2a05

Please sign in to comment.