From f4d20200b1be53c5319bd78d8827ec99c94ce823 Mon Sep 17 00:00:00 2001 From: Trevor Pilley Date: Mon, 15 Apr 2024 13:00:21 +0100 Subject: [PATCH] C# 8 Empty ReadOnlyCollection --- src/PhoneNumbers/CountryInfo.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/PhoneNumbers/CountryInfo.cs b/src/PhoneNumbers/CountryInfo.cs index 10982a97..2a5b5daa 100644 --- a/src/PhoneNumbers/CountryInfo.cs +++ b/src/PhoneNumbers/CountryInfo.cs @@ -18,7 +18,10 @@ public sealed partial class CountryInfo internal const string NorthAmerica = "North America"; internal const string Oceania = "Oceania"; internal const string SouthAmerica = "South America"; + #if !NET8_0_OR_GREATER private static readonly ReadOnlyCollection s_emptyIntArray = new(Array.Empty()); + #endif + private static readonly ReadOnlyCollection s_formatters = new( [ E164PhoneNumberFormatter.Instance, @@ -96,12 +99,22 @@ internal CountryInfo() /// /// Gets the possible lengths of the national destination code. /// - internal ReadOnlyCollection NdcLengths { get; init; } = s_emptyIntArray; + internal ReadOnlyCollection NdcLengths { get; init; } = + #if NET8_0_OR_GREATER + ReadOnlyCollection.Empty; + #else + s_emptyIntArray; + #endif /// /// Gets the permitted lengths of the national significant number. /// - internal ReadOnlyCollection NsnLengths { get; init; } = s_emptyIntArray; + internal ReadOnlyCollection NsnLengths { get; init; } = + #if NET8_0_OR_GREATER + ReadOnlyCollection.Empty; + #else + s_emptyIntArray; + #endif internal static IEnumerable GetCountries() => typeof(CountryInfo)