|
1 | 1 | <#@ template language="C#" hostspecific="true" #> |
2 | 2 | <#@ assembly name="System" #> |
3 | 3 | <#@ assembly name="System.Core" #> |
4 | | -<#@ assembly name="System.Web.Extensions" #> |
| 4 | +<#@ assembly name="System.Text.Json" #> |
5 | 5 | <#@ import namespace="System.IO" #> |
6 | 6 | <#@ import namespace="System.Linq" #> |
7 | 7 | <#@ import namespace="System.Text" #> |
8 | 8 | <#@ import namespace="System.Collections.Generic" #> |
9 | 9 | <#@ import namespace="System.Text.RegularExpressions" #> |
10 | | -<#@ import namespace="System.Web.Script.Serialization" #> |
| 10 | +<#@ import namespace="System.Text.Json" #> |
11 | 11 | <# |
12 | | - var filesForCountries = new Dictionary<string, string[]> { |
| 12 | + var filesForCountries = new Dictionary<string, string[]> { |
13 | 13 | { "3Digits.json", new [] { "FO", "IS", "LS", "MG", "OM", "PG", "PS" }}, |
14 | 14 | { "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" }}, |
15 | 15 | { "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" }}, |
16 | 16 | { "6Digits.json", new [] { "BY", "CN", "CO", "EC", "IN", "KG", "KZ", "NG", "PA", "RO", "SG", "TJ", "TM", "TT", "VN" }}, |
17 | 17 | { "7Digits.json", new [] { "IL", "JP" }} |
18 | 18 | }; |
19 | 19 |
|
20 | | - var js = new System.Web.Script.Serialization.JavaScriptSerializer (); |
| 20 | + var jsonOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; |
21 | 21 | var countryList = new HashSet<CountryInfo>(); |
22 | 22 |
|
23 | 23 | 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 | | - } |
34 | 24 |
|
35 | 25 | var jsonFiles = Directory.GetFiles(Path.Combine(templateDirectory, "../../countries/")).Where(a => a.EndsWith(".json")); |
36 | 26 | var regex = new Regex(@"^([A-Z]{2})\.json$"); |
37 | 27 | foreach (var jsonFile in jsonFiles) |
38 | 28 | { |
39 | | - |
| 29 | + |
40 | 30 | var match = regex.Match(Path.GetFileName(jsonFile)); |
41 | 31 | if (match.Success) |
42 | 32 | { |
43 | | - var ci = js.Deserialize<CountryInfo>(File.ReadAllText(jsonFile)); |
| 33 | + var ci = JsonSerializer.Deserialize<CountryInfo>(File.ReadAllText(jsonFile), jsonOptions); |
44 | 34 | 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 | + } |
47 | 48 |
|
48 | 49 | var countrySortedList = countryList.OrderBy(a => a.CountryCodeAlpha2).ToList(); |
49 | 50 | foreach(var countryInfo in countryList) |
|
0 commit comments