Skip to content

Commit

Permalink
C# 8 Empty ReadOnlyCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorPilley committed Apr 15, 2024
1 parent d933ec4 commit 35133c4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/PhoneNumbers/CountryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> s_emptyIntArray = new(Array.Empty<int>());
#endif

private static readonly ReadOnlyCollection<PhoneNumberFormatter> s_formatters = new(
[
E164PhoneNumberFormatter.Instance,
Expand Down Expand Up @@ -96,12 +99,22 @@ internal CountryInfo()
/// <summary>
/// Gets the possible lengths of the national destination code.
/// </summary>
internal ReadOnlyCollection<int> NdcLengths { get; init; } = s_emptyIntArray;
internal ReadOnlyCollection<int> NdcLengths { get; init; } =
#if NET8_0_OR_GREATER
ReadOnlyCollection<int>.Empty;
#else
s_emptyIntArray;
#endif

/// <summary>
/// Gets the permitted lengths of the national significant number.
/// </summary>
internal ReadOnlyCollection<int> NsnLengths { get; init; } = s_emptyIntArray;
internal ReadOnlyCollection<int> NsnLengths { get; init; } =
#if NET8_0_OR_GREATER
ReadOnlyCollection<int>.Empty;
#else
s_emptyIntArray;
#endif

internal static IEnumerable<CountryInfo> GetCountries() =>
typeof(CountryInfo)
Expand Down

0 comments on commit 35133c4

Please sign in to comment.