Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# 8 Empty ReadOnlyCollection #635

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading