From e83d3dc90f0e2e8a822156c83bb518079c423782 Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Mon, 20 Nov 2023 11:24:35 +0000 Subject: [PATCH 1/6] Target .NET 8.0 --- .devcontainer/devcontainer.json | 2 +- .github/workflows/CI.yml | 2 +- .github/workflows/publish.yml | 2 +- NuGet.md | 2 +- README.md | 2 +- src/PhoneNumbers/PhoneNumbers.csproj | 6 +----- test/PhoneNumbers.Data.Tests/PhoneNumbers.Data.Tests.csproj | 2 +- test/PhoneNumbers.Tests/PhoneNumbers.Tests.csproj | 2 +- 8 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e35f5f48..8edc2808 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ { "name": "C# (.NET)", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/dotnet:7.0", + "image": "mcr.microsoft.com/devcontainers/dotnet:8.0", // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 86cb5410..b5a578bd 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -55,7 +55,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name : dotnet restore run: dotnet restore diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 562ce433..5126cc3a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -46,7 +46,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 7.0.x + dotnet-version: 8.0.x - name: Set release version if: github.ref_type == 'tag' diff --git a/NuGet.md b/NuGet.md index 7287f815..7b8425d0 100644 --- a/NuGet.md +++ b/NuGet.md @@ -31,7 +31,7 @@ phoneNumber.ToString("RFC3966"); // tel:+44-114-272-644 (RFC3966 format) Builds for: -- .NET 7.0 +- .NET 8.0 - .NET Standard 2.1 - _supports .NET Core 3.0 or newer and .NET 5.0 or newer_ - .NET Standard 2.0 - _supports .NET Framework 4.6.2 or newer, however projects will need to be built with a minimum C# language version of 9.0 due to use of init only properties_ diff --git a/README.md b/README.md index d70ec9d8..46b6972c 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ The library adheres to [Semantic Versioning](https://semver.org) and [release no Specific builds are included in the nuget package for: -- .NET 7.0 +- .NET 8.0 - .NET Standard 2.1 - _supports .NET Core 3.0 or newer and .NET 5.0 or newer_ - .NET Standard 2.0 - _supports .NET Framework 4.6.2 or newer, however projects will need to be built with a minimum C# language version of 9.0 due to use of init only properties_ diff --git a/src/PhoneNumbers/PhoneNumbers.csproj b/src/PhoneNumbers/PhoneNumbers.csproj index 3fc6cfa2..f9070f62 100644 --- a/src/PhoneNumbers/PhoneNumbers.csproj +++ b/src/PhoneNumbers/PhoneNumbers.csproj @@ -3,7 +3,7 @@ PhoneNumbers PhoneNumbers - net7.0;netstandard2.1;netstandard2.0 + net8.0;netstandard2.1;netstandard2.0 11.0 enable AllEnabledByDefault @@ -42,10 +42,6 @@ - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/PhoneNumbers.Data.Tests/PhoneNumbers.Data.Tests.csproj b/test/PhoneNumbers.Data.Tests/PhoneNumbers.Data.Tests.csproj index 7d629da8..5253a88b 100644 --- a/test/PhoneNumbers.Data.Tests/PhoneNumbers.Data.Tests.csproj +++ b/test/PhoneNumbers.Data.Tests/PhoneNumbers.Data.Tests.csproj @@ -3,7 +3,7 @@ PhoneNumbers.Data.Tests PhoneNumbers.Tests - net7.0 + net8.0 false true ..\..\PhoneNumbers.snk diff --git a/test/PhoneNumbers.Tests/PhoneNumbers.Tests.csproj b/test/PhoneNumbers.Tests/PhoneNumbers.Tests.csproj index 4094565f..8da773ca 100644 --- a/test/PhoneNumbers.Tests/PhoneNumbers.Tests.csproj +++ b/test/PhoneNumbers.Tests/PhoneNumbers.Tests.csproj @@ -3,7 +3,7 @@ PhoneNumbers.Tests PhoneNumbers.Tests - net7.0 + net8.0 false true ..\..\PhoneNumbers.snk From ba3fb4de4d8aed5f03d82aa4f5c108251aa5b463 Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Mon, 20 Nov 2023 11:41:51 +0000 Subject: [PATCH 2/6] CA1859 Use concrete types when possible for improved performance --- src/PhoneNumbers/Parsers/ResourceUtility.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PhoneNumbers/Parsers/ResourceUtility.cs b/src/PhoneNumbers/Parsers/ResourceUtility.cs index 26a9eb0b..ec5cf0da 100644 --- a/src/PhoneNumbers/Parsers/ResourceUtility.cs +++ b/src/PhoneNumbers/Parsers/ResourceUtility.cs @@ -1,3 +1,4 @@ +using System.Collections.ObjectModel; using System.Reflection; namespace PhoneNumbers.Parsers; @@ -43,7 +44,7 @@ private static PhoneNumberKind ParseNumberKind(char value) => _ => throw new NotSupportedException(value.ToString()), }; - private static IReadOnlyList ParseNumberRanges(string value) => + private static ReadOnlyCollection ParseNumberRanges(string value) => value .Split(Chars.Comma) .Select(NumberRange.Create) From e6eae5accfbbe46471fc2a86a5a63babb29eb947 Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Mon, 20 Nov 2023 11:45:08 +0000 Subject: [PATCH 3/6] Ignore CA1510, API not in NETSTANDARD --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index e7131d02..f9a65ecc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -172,6 +172,9 @@ dotnet_diagnostic.CA1305.severity = error # CA1310: Specify StringComparison for correctness dotnet_diagnostic.CA1310.severity = error +# CA1510: Use ArgumentNullException throw helper +dotnet_diagnostic.CA1510.severity = none + # SA1101: Prefix local calls with this dotnet_diagnostic.SA1101.severity = none From 8f3678601d03d7853e5f2e94526a1b5b77ca6ceb Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Mon, 20 Nov 2023 11:47:44 +0000 Subject: [PATCH 4/6] Remove obsolete constructor --- src/PhoneNumbers/ParseException.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/PhoneNumbers/ParseException.cs b/src/PhoneNumbers/ParseException.cs index c90b7f53..87513a67 100644 --- a/src/PhoneNumbers/ParseException.cs +++ b/src/PhoneNumbers/ParseException.cs @@ -5,7 +5,6 @@ namespace PhoneNumbers; /// /// An exception thrown when there is an issue parsing a phone number. /// -[Serializable] [System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] public class ParseException : Exception { @@ -34,14 +33,4 @@ public ParseException(string? message, Exception? innerException) : base(message, innerException) { } - - /// - /// Initializes a new instance of the class. - /// - /// The that holds the serialized object data about the exception being thrown. - /// The that contains contextual information about the source or destination. - protected ParseException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } From 066891462479148b1055bdc7ace400ea162b980a Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Mon, 20 Nov 2023 12:19:24 +0000 Subject: [PATCH 5/6] C# 12 --- src/PhoneNumbers/PhoneNumbers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhoneNumbers/PhoneNumbers.csproj b/src/PhoneNumbers/PhoneNumbers.csproj index f9070f62..8dae1d93 100644 --- a/src/PhoneNumbers/PhoneNumbers.csproj +++ b/src/PhoneNumbers/PhoneNumbers.csproj @@ -4,7 +4,7 @@ PhoneNumbers PhoneNumbers net8.0;netstandard2.1;netstandard2.0 - 11.0 + 12.0 enable AllEnabledByDefault true From 724c2e15dc86f88993a4feec2ce690e8756c4d54 Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Tue, 21 Nov 2023 11:06:40 +0000 Subject: [PATCH 6/6] Collection expressions --- CONTRIBUTING.md | 2 +- src/PhoneNumbers/CountryInfo.cs | 6 +- src/PhoneNumbers/CountryInfo_Africa.cs | 16 +- src/PhoneNumbers/CountryInfo_Asia.cs | 6 +- src/PhoneNumbers/CountryInfo_Europe.cs | 150 +++++++++---------- src/PhoneNumbers/CountryInfo_NorthAmerica.cs | 4 +- src/PhoneNumbers/CountryInfo_Oceania.cs | 8 +- src/PhoneNumbers/CountryInfo_SouthAmerica.cs | 4 +- test/PhoneNumbers.Tests/ParseOptionsTests.cs | 2 +- 9 files changed, 99 insertions(+), 99 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4d1a4413..5fb2e725 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ public static CountryInfo CountryName { get; } = new() Continent = Africa/Asia/Europe/Oceania/NorthAmerica/SouthAmerica, // as appropriate Iso3166Code = "ZZ", Name = "CountryName", - NsnLengths = new ReadOnlyCollection(new[] { N }), + NsnLengths = new ReadOnlyCollection([N]), }; ``` diff --git a/src/PhoneNumbers/CountryInfo.cs b/src/PhoneNumbers/CountryInfo.cs index a7902220..085a6f8e 100644 --- a/src/PhoneNumbers/CountryInfo.cs +++ b/src/PhoneNumbers/CountryInfo.cs @@ -19,13 +19,13 @@ public sealed partial class CountryInfo internal const string Oceania = "Oceania"; internal const string SouthAmerica = "South America"; private static readonly ReadOnlyCollection s_emptyIntArray = new(Array.Empty()); - private static readonly ReadOnlyCollection s_formatters = new(new[] - { + private static readonly ReadOnlyCollection s_formatters = new( + [ E164PhoneNumberFormatter.Instance, E123PhoneNumberFormatter.Instance, NationalPhoneNumberFormatter.Instance, Rfc3966PhoneNumberFormatter.Instance, - }); + ]); /// /// Initialises a new instance of the class. diff --git a/src/PhoneNumbers/CountryInfo_Africa.cs b/src/PhoneNumbers/CountryInfo_Africa.cs index 6ba7e22c..cc8297a1 100644 --- a/src/PhoneNumbers/CountryInfo_Africa.cs +++ b/src/PhoneNumbers/CountryInfo_Africa.cs @@ -14,8 +14,8 @@ public partial class CountryInfo Continent = Africa, Iso3166Code = "EG", Name = "Egypt", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 9, 10, 11 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([8, 9, 10, 11]), TrunkPrefix = "0", }; @@ -29,8 +29,8 @@ public partial class CountryInfo FormatProvider = SimplePhoneNumberFormatProvider.Default, Iso3166Code = "KE", Name = "Kenya", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 7, 8, 9, 12 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([7, 8, 9, 12]), TrunkPrefix = "0", }; @@ -44,8 +44,8 @@ public partial class CountryInfo Continent = Africa, Iso3166Code = "NG", Name = "Nigeria", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 10 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([8, 10]), TrunkPrefix = "0", }; @@ -58,8 +58,8 @@ public partial class CountryInfo Continent = Africa, Iso3166Code = "ZA", Name = "South Africa", - NdcLengths = new ReadOnlyCollection(new[] { 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 9, 13 }), + NdcLengths = new ReadOnlyCollection([2]), + NsnLengths = new ReadOnlyCollection([9, 13]), TrunkPrefix = "0", }; } diff --git a/src/PhoneNumbers/CountryInfo_Asia.cs b/src/PhoneNumbers/CountryInfo_Asia.cs index 524a3481..c6276433 100644 --- a/src/PhoneNumbers/CountryInfo_Asia.cs +++ b/src/PhoneNumbers/CountryInfo_Asia.cs @@ -13,7 +13,7 @@ public partial class CountryInfo Continent = Asia, Iso3166Code = "HK", Name = "Hong Kong", - NsnLengths = new ReadOnlyCollection(new[] { 8, 9, 12 }), + NsnLengths = new ReadOnlyCollection([8, 9, 12]), }; /// @@ -25,7 +25,7 @@ public partial class CountryInfo Continent = Asia, Iso3166Code = "MO", Name = "Macau", - NsnLengths = new ReadOnlyCollection(new[] { 8 }), + NsnLengths = new ReadOnlyCollection([8]), }; /// @@ -37,6 +37,6 @@ public partial class CountryInfo Continent = Asia, Iso3166Code = "SG", Name = "Singapore", - NsnLengths = new ReadOnlyCollection(new[] { 8, 10, 11 }), + NsnLengths = new ReadOnlyCollection([8, 10, 11]), }; } diff --git a/src/PhoneNumbers/CountryInfo_Europe.cs b/src/PhoneNumbers/CountryInfo_Europe.cs index 88e05034..21f01d3f 100644 --- a/src/PhoneNumbers/CountryInfo_Europe.cs +++ b/src/PhoneNumbers/CountryInfo_Europe.cs @@ -15,8 +15,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "AT", Name = "Austria", - NdcLengths = new ReadOnlyCollection(new[] { 4, 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }), + NdcLengths = new ReadOnlyCollection([4, 3, 2, 1]), + NsnLengths = new ReadOnlyCollection([4, 5, 6, 7, 8, 9, 10, 11, 12, 13]), TrunkPrefix = "0", }; @@ -30,8 +30,8 @@ public partial class CountryInfo Iso3166Code = "BY", FormatProvider = SimplePhoneNumberFormatProvider.Default, Name = "Belarus", - NdcLengths = new ReadOnlyCollection(new[] { 4, 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 6, 9, 10, 11 }), + NdcLengths = new ReadOnlyCollection([4, 3, 2]), + NsnLengths = new ReadOnlyCollection([6, 9, 10, 11]), TrunkPrefix = "8", }; @@ -46,8 +46,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "BE", Name = "Belgium", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 9 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([8, 9]), TrunkPrefix = "0", }; @@ -62,8 +62,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "BG", Name = "Bulgaria", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 9, 12 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([8, 9, 12]), TrunkPrefix = "0", }; @@ -78,8 +78,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "HR", Name = "Croatia", - NdcLengths = new ReadOnlyCollection(new[] { 5, 4, 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 6, 7, 8, 9, 10 }), + NdcLengths = new ReadOnlyCollection([5, 4, 3, 2, 1]), + NsnLengths = new ReadOnlyCollection([6, 7, 8, 9, 10]), TrunkPrefix = "0", }; @@ -94,8 +94,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "CY", Name = "Cyprus", - NdcLengths = new ReadOnlyCollection(new[] { 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 8 }), + NdcLengths = new ReadOnlyCollection([2]), + NsnLengths = new ReadOnlyCollection([8]), }; /// @@ -109,8 +109,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "CZ", Name = "Czech Republic", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 7, 9, 10, 11, 12 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([7, 9, 10, 11, 12]), }; /// @@ -123,7 +123,7 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "DK", Name = "Denmark", - NsnLengths = new ReadOnlyCollection(new[] { 8 }), + NsnLengths = new ReadOnlyCollection([8]), }; /// @@ -137,8 +137,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "EE", Name = "Estonia", - NdcLengths = new ReadOnlyCollection(new[] { 4, 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 7, 8, 10, 12 }), + NdcLengths = new ReadOnlyCollection([4, 3, 2]), + NsnLengths = new ReadOnlyCollection([7, 8, 10, 12]), }; /// @@ -152,8 +152,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "FI", Name = "Finland", - NdcLengths = new ReadOnlyCollection(new[] { 4, 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 5, 6, 7, 8, 9, 10, 11, 12 }), + NdcLengths = new ReadOnlyCollection([4, 3, 2, 1]), + NsnLengths = new ReadOnlyCollection([5, 6, 7, 8, 9, 10, 11, 12]), TrunkPrefix = "0", }; @@ -168,7 +168,7 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "FR", Name = "France", - NsnLengths = new ReadOnlyCollection(new[] { 9, 13 }), + NsnLengths = new ReadOnlyCollection([9, 13]), TrunkPrefix = "0", }; @@ -183,8 +183,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "DE", Name = "Germany", - NdcLengths = new ReadOnlyCollection(new[] { 5, 4, 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }), + NdcLengths = new ReadOnlyCollection([5, 4, 3, 2]), + NsnLengths = new ReadOnlyCollection([4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]), TrunkPrefix = "0", }; @@ -198,8 +198,8 @@ public partial class CountryInfo FormatProvider = BasicPhoneNumberFormatProvider.Instance, Iso3166Code = "GI", Name = "Gibraltar", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 4, 8 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([4, 8]), }; /// @@ -213,8 +213,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "GR", Name = "Greece", - NdcLengths = new ReadOnlyCollection(new[] { 4, 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 10 }), + NdcLengths = new ReadOnlyCollection([4, 3, 2]), + NsnLengths = new ReadOnlyCollection([10]), }; /// @@ -228,8 +228,8 @@ public partial class CountryInfo FormatProvider = GBPhoneNumberFormatProvider.Instance, Iso3166Code = "GG", Name = "Guernsey", - NdcLengths = new ReadOnlyCollection(new[] { 4 }), - NsnLengths = new ReadOnlyCollection(new[] { 10 }), + NdcLengths = new ReadOnlyCollection([4]), + NsnLengths = new ReadOnlyCollection([10]), SharesCallingCode = true, TrunkPrefix = "0", }; @@ -245,8 +245,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "HU", Name = "Hungary", - NdcLengths = new ReadOnlyCollection(new[] { 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 9, 12 }), + NdcLengths = new ReadOnlyCollection([2, 1]), + NsnLengths = new ReadOnlyCollection([8, 9, 12]), TrunkPrefix = "06", }; @@ -262,8 +262,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "IE", Name = "Ireland", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 7, 8, 9, 12 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([7, 8, 9, 12]), TrunkPrefix = "0", }; @@ -278,8 +278,8 @@ public partial class CountryInfo FormatProvider = GBPhoneNumberFormatProvider.Instance, Iso3166Code = "IM", Name = "Isle of Man", - NdcLengths = new ReadOnlyCollection(new[] { 4 }), - NsnLengths = new ReadOnlyCollection(new[] { 10 }), + NdcLengths = new ReadOnlyCollection([4]), + NsnLengths = new ReadOnlyCollection([10]), SharesCallingCode = true, TrunkPrefix = "0", }; @@ -296,8 +296,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "IT", Name = "Italy", - NdcLengths = new ReadOnlyCollection(new[] { 5, 4, 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 5, 6, 7, 8, 9, 10, 11 }), + NdcLengths = new ReadOnlyCollection([5, 4, 3, 2]), + NsnLengths = new ReadOnlyCollection([5, 6, 7, 8, 9, 10, 11]), }; /// @@ -311,8 +311,8 @@ public partial class CountryInfo FormatProvider = GBPhoneNumberFormatProvider.Instance, Iso3166Code = "JE", Name = "Jersey", - NdcLengths = new ReadOnlyCollection(new[] { 4 }), - NsnLengths = new ReadOnlyCollection(new[] { 10 }), + NdcLengths = new ReadOnlyCollection([4]), + NsnLengths = new ReadOnlyCollection([10]), SharesCallingCode = true, TrunkPrefix = "0", }; @@ -327,8 +327,8 @@ public partial class CountryInfo Continent = Europe, Iso3166Code = "XK", Name = "Kosovo", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 9 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([8, 9]), TrunkPrefix = "0", }; @@ -343,7 +343,7 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "LV", Name = "Latvia", - NsnLengths = new ReadOnlyCollection(new[] { 8 }), + NsnLengths = new ReadOnlyCollection([8]), }; /// @@ -357,8 +357,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "LT", Name = "Lithuania", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 8 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([8]), TrunkPrefix = "8", }; @@ -373,7 +373,7 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "LU", Name = "Luxembourg", - NsnLengths = new ReadOnlyCollection(new[] { 4, 5, 6, 7, 8, 9, 10, 11, 12 }), + NsnLengths = new ReadOnlyCollection([4, 5, 6, 7, 8, 9, 10, 11, 12]), }; /// @@ -387,8 +387,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "MT", Name = "Malta", - NdcLengths = new ReadOnlyCollection(new[] { 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 10 }), + NdcLengths = new ReadOnlyCollection([2]), + NsnLengths = new ReadOnlyCollection([8, 10]), }; /// @@ -400,8 +400,8 @@ public partial class CountryInfo Continent = Europe, Iso3166Code = "MD", Name = "Moldova", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 5, 6, 7, 8 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([5, 6, 7, 8]), TrunkPrefix = "0", }; @@ -415,7 +415,7 @@ public partial class CountryInfo FormatProvider = MCPhoneNumberFormatProvider.Instance, Iso3166Code = "MC", Name = "Monaco", - NsnLengths = new ReadOnlyCollection(new[] { 8, 9, 12 }), + NsnLengths = new ReadOnlyCollection([8, 9, 12]), }; /// @@ -429,8 +429,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "NL", Name = "Netherlands", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 9 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([9]), TrunkPrefix = "0", }; @@ -444,7 +444,7 @@ public partial class CountryInfo FormatProvider = NOPhoneNumberFormatProvider.Instance, Iso3166Code = "NO", Name = "Norway", - NsnLengths = new ReadOnlyCollection(new[] { 8, 12 }), + NsnLengths = new ReadOnlyCollection([8, 12]), }; /// @@ -458,8 +458,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "PL", Name = "Poland", - NdcLengths = new ReadOnlyCollection(new[] { 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 6, 7, 8, 9 }), + NdcLengths = new ReadOnlyCollection([2]), + NsnLengths = new ReadOnlyCollection([6, 7, 8, 9]), }; /// @@ -472,8 +472,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "PT", Name = "Portugal", - NdcLengths = new ReadOnlyCollection(new[] { 3 }), - NsnLengths = new ReadOnlyCollection(new[] { 9 }), + NdcLengths = new ReadOnlyCollection([3]), + NsnLengths = new ReadOnlyCollection([9]), }; /// @@ -487,8 +487,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "RO", Name = "Romania", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 6, 7, 8, 9 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([6, 7, 8, 9]), TrunkPrefix = "0", }; @@ -502,7 +502,7 @@ public partial class CountryInfo FormatProvider = SimplePhoneNumberFormatProvider.Default, Iso3166Code = "SM", Name = "San Marino", - NsnLengths = new ReadOnlyCollection(new[] { 6, 7, 8, 9, 10 }), + NsnLengths = new ReadOnlyCollection([6, 7, 8, 9, 10]), }; /// @@ -515,8 +515,8 @@ public partial class CountryInfo Continent = Europe, Iso3166Code = "RS", Name = "Serbia", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 9, 10, 11, 12 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([8, 9, 10, 11, 12]), TrunkPrefix = "0", }; @@ -530,8 +530,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "SK", Name = "Slovakia", - NdcLengths = new ReadOnlyCollection(new[] { 4, 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 7, 9 }), + NdcLengths = new ReadOnlyCollection([4, 3, 2, 1]), + NsnLengths = new ReadOnlyCollection([7, 9]), TrunkPrefix = "0", }; @@ -547,8 +547,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "SL", Name = "Slovenia", - NdcLengths = new ReadOnlyCollection(new[] { 4, 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 8, 12 }), + NdcLengths = new ReadOnlyCollection([4, 3, 2, 1]), + NsnLengths = new ReadOnlyCollection([8, 12]), TrunkPrefix = "0", }; @@ -563,8 +563,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "ES", Name = "Spain", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 9, 13 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([9, 13]), }; /// @@ -579,8 +579,8 @@ public partial class CountryInfo IsEuropeanUnionMember = true, Iso3166Code = "SE", Name = "Sweden", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 6, 7, 8, 9, 10, 13 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([6, 7, 8, 9, 10, 13]), TrunkPrefix = "0", }; @@ -594,8 +594,8 @@ public partial class CountryInfo FormatProvider = CHPhoneNumberFormatProvider.Instance, Iso3166Code = "CH", Name = "Switzerland", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 9 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([9]), TrunkPrefix = "0", }; @@ -610,8 +610,8 @@ public partial class CountryInfo FormatProvider = UAPhoneNumberFormatProvider.Instance, Iso3166Code = "UA", Name = "Ukraine", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 9, 10 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([9, 10]), TrunkPrefix = "0", }; @@ -627,8 +627,8 @@ public partial class CountryInfo FormatProvider = GBPhoneNumberFormatProvider.Instance, Iso3166Code = "GB", Name = "United Kingdom", - NdcLengths = new ReadOnlyCollection(new[] { 5, 4, 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 7, 9, 10 }), + NdcLengths = new ReadOnlyCollection([5, 4, 3, 2]), + NsnLengths = new ReadOnlyCollection([7, 9, 10]), TrunkPrefix = "0", }; } diff --git a/src/PhoneNumbers/CountryInfo_NorthAmerica.cs b/src/PhoneNumbers/CountryInfo_NorthAmerica.cs index 901af034..b04e2770 100644 --- a/src/PhoneNumbers/CountryInfo_NorthAmerica.cs +++ b/src/PhoneNumbers/CountryInfo_NorthAmerica.cs @@ -6,8 +6,8 @@ namespace PhoneNumbers; public partial class CountryInfo { internal const string NanpCallingCode = "1"; - private static readonly ReadOnlyCollection s_nanpNdcLengths = new(new[] { 3 }); - private static readonly ReadOnlyCollection s_nanpNsnLengths = new(new[] { 10 }); + private static readonly ReadOnlyCollection s_nanpNdcLengths = new([3]); + private static readonly ReadOnlyCollection s_nanpNsnLengths = new([10]); /// /// Gets the for Anguilla. diff --git a/src/PhoneNumbers/CountryInfo_Oceania.cs b/src/PhoneNumbers/CountryInfo_Oceania.cs index 4b2579e8..cda854c0 100644 --- a/src/PhoneNumbers/CountryInfo_Oceania.cs +++ b/src/PhoneNumbers/CountryInfo_Oceania.cs @@ -32,8 +32,8 @@ public partial class CountryInfo FormatProvider = AUPhoneNumberFormatProvider.Instance, Iso3166Code = "AU", Name = "Australia", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2, 1 }), - NsnLengths = new ReadOnlyCollection(new[] { 5, 6, 7, 8, 9, 10 }), + NdcLengths = new ReadOnlyCollection([3, 2, 1]), + NsnLengths = new ReadOnlyCollection([5, 6, 7, 8, 9, 10]), TrunkPrefix = "0", }; @@ -62,7 +62,7 @@ public partial class CountryInfo Continent = Oceania, Iso3166Code = "PG", Name = "Papua New Guinea", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 7, 8 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([7, 8]), }; } diff --git a/src/PhoneNumbers/CountryInfo_SouthAmerica.cs b/src/PhoneNumbers/CountryInfo_SouthAmerica.cs index f38954d7..6e6a8600 100644 --- a/src/PhoneNumbers/CountryInfo_SouthAmerica.cs +++ b/src/PhoneNumbers/CountryInfo_SouthAmerica.cs @@ -16,8 +16,8 @@ public partial class CountryInfo FormatProvider = BRPhoneNumberFormatProvider.Instance, Iso3166Code = "BR", Name = "Brazil", - NdcLengths = new ReadOnlyCollection(new[] { 3, 2 }), - NsnLengths = new ReadOnlyCollection(new[] { 10, 11 }), + NdcLengths = new ReadOnlyCollection([3, 2]), + NsnLengths = new ReadOnlyCollection([10, 11]), TrunkPrefix = "0", }; } diff --git a/test/PhoneNumbers.Tests/ParseOptionsTests.cs b/test/PhoneNumbers.Tests/ParseOptionsTests.cs index 1de5ecf2..a3b3a419 100644 --- a/test/PhoneNumbers.Tests/ParseOptionsTests.cs +++ b/test/PhoneNumbers.Tests/ParseOptionsTests.cs @@ -136,7 +136,7 @@ public void Extensions_Throw_If_ParseOptions_Null() .ToList() .ForEach(x => { - var exception = Assert.Throws(() => x.Invoke(null, new [] { parseOptions })); + var exception = Assert.Throws(() => x.Invoke(null, [parseOptions])); Assert.IsType(exception.InnerException); }); }