Skip to content

Commit 6e8200c

Browse files
author
Filip Staffa
committed
switch to t4 cli, update country definitions to correspond to code
1 parent 1dea354 commit 6e8200c

22 files changed

Lines changed: 988 additions & 29 deletions

.github/workflows/dotnetcore.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ jobs:
2929
uses: actions/setup-dotnet@v3
3030
with:
3131
dotnet-version: 8.0.x
32+
- name: Setup .NET 9
33+
uses: actions/setup-dotnet@v3
34+
with:
35+
dotnet-version: 9.0.x
36+
- name: Setup .NET 10
37+
uses: actions/setup-dotnet@v3
38+
with:
39+
dotnet-version: 10.0.x
40+
- name: Restore dotnet tools
41+
run: dotnet tool restore
42+
- name: Regenerate from T4
43+
run: dotnet t4 src/PostalCodes/Generated/PostalCodeFactory.gen.tt
44+
- name: Verify no drift
45+
run: git diff --exit-code
3246
- name: Build with dotnet
3347
run: dotnet build --configuration Release /p:ContinuousIntegrationBuild=true
3448
- name: Test

src/PostalCodes.UnitTests/PostalCodes.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp2.2;netcoreapp3.1;net6.0;net8.0</TargetFrameworks>
3+
<TargetFrameworks>netcoreapp2.2;netcoreapp3.1;net6.0;net8.0;net9.0;net10.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />

src/PostalCodes/Generated/PostalCodeFactory.gen.tt

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
11
<#@ template language="C#" hostspecific="true" #>
22
<#@ assembly name="System" #>
33
<#@ assembly name="System.Core" #>
4-
<#@ assembly name="System.Web.Extensions" #>
4+
<#@ assembly name="System.Text.Json" #>
55
<#@ import namespace="System.IO" #>
66
<#@ import namespace="System.Linq" #>
77
<#@ import namespace="System.Text" #>
88
<#@ import namespace="System.Collections.Generic" #>
99
<#@ import namespace="System.Text.RegularExpressions" #>
10-
<#@ import namespace="System.Web.Script.Serialization" #>
10+
<#@ import namespace="System.Text.Json" #>
1111
<#
12-
var filesForCountries = new Dictionary<string, string[]> {
12+
var filesForCountries = new Dictionary<string, string[]> {
1313
{ "3Digits.json", new [] { "FO", "IS", "LS", "MG", "OM", "PG", "PS" }},
1414
{ "4Digits.json", new [] { "AF", "AL", "AM", "AR", "AT", "AU", "BD", "BE", "BE", "BG", "BO", "CC", "CH", "CV", "CX", "CY", "CY", "DK", "ET", "GE", "GL", "GW", "HM", "HT", "HU", "HU", "LI", "LR", "LU", "MK", "MZ", "NE", "NF", "NO", "NO", "NZ", "PH", "PY", "SI", "SJ", "TN", "ZA" }},
1515
{ "5Digits.json", new [] { "AS", "BA", "BT", "CR", "CU", "CZ", "DE", "DO", "DZ", "EE", "EG", "ES", "FI", "FM", "FR", "GR", "GT", "GU", "HN", "HR", "HR", "ID", "IQ", "IT", "JO", "KE", "KH", "KW", "LA", "LK", "LY", "MA", "MC", "ME", "MH", "MM", "MN", "MP", "MQ", "MU", "MX", "MY", "NA", "NI", "NP", "PE", "PK", "PR", "PW", "RS", "SD", "SE", "SK", "SN", "TD", "TH", "TR", "TW", "UA", "UY", "VI", "YT", "ZM" }},
1616
{ "6Digits.json", new [] { "BY", "CN", "CO", "EC", "IN", "KG", "KZ", "NG", "PA", "RO", "SG", "TJ", "TM", "TT", "VN" }},
1717
{ "7Digits.json", new [] { "IL", "JP" }}
1818
};
1919

20-
var js = new System.Web.Script.Serialization.JavaScriptSerializer ();
20+
var jsonOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
2121
var countryList = new HashSet<CountryInfo>();
2222

2323
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
24-
foreach(var fileType in filesForCountries)
25-
{
26-
foreach(var countryCode in fileType.Value)
27-
{
28-
var ci = js.Deserialize<CountryInfo>(File.ReadAllText(Path.Combine(templateDirectory, "../../countries", fileType.Key)));
29-
ci.CountryCodeAlpha2 = countryCode;
30-
ci.CountryName = countryCode;
31-
countryList.Add( ci );
32-
}
33-
}
3424

3525
var jsonFiles = Directory.GetFiles(Path.Combine(templateDirectory, "../../countries/")).Where(a => a.EndsWith(".json"));
3626
var regex = new Regex(@"^([A-Z]{2})\.json$");
3727
foreach (var jsonFile in jsonFiles)
3828
{
39-
29+
4030
var match = regex.Match(Path.GetFileName(jsonFile));
4131
if (match.Success)
4232
{
43-
var ci = js.Deserialize<CountryInfo>(File.ReadAllText(jsonFile));
33+
var ci = JsonSerializer.Deserialize<CountryInfo>(File.ReadAllText(jsonFile), jsonOptions);
4434
countryList.Add( ci );
45-
}
46-
}
35+
}
36+
}
37+
38+
foreach(var fileType in filesForCountries)
39+
{
40+
foreach(var countryCode in fileType.Value)
41+
{
42+
var ci = JsonSerializer.Deserialize<CountryInfo>(File.ReadAllText(Path.Combine(templateDirectory, "../../countries", fileType.Key)), jsonOptions);
43+
ci.CountryCodeAlpha2 = countryCode;
44+
ci.CountryName = countryCode;
45+
countryList.Add( ci );
46+
}
47+
}
4748

4849
var countrySortedList = countryList.OrderBy(a => a.CountryCodeAlpha2).ToList();
4950
foreach(var countryInfo in countryList)

0 commit comments

Comments
 (0)