Skip to content

Commit 2cb944c

Browse files
meziantouCopilot
andcommitted
Fix C#13 polyfill compilation compatibility
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 452b139 commit 2cb944c

12 files changed

+66
-18
lines changed

Meziantou.Polyfill.Editor/M;System.Collections.Generic.CollectionExtensions.AddRange``1(System.Collections.Generic.List{``0},System.ReadOnlySpan{``0}).cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ static partial class PolyfillExtensions
1010
/// <exception cref="ArgumentNullException">The <paramref name="list"/> is null.</exception>
1111
public static void AddRange<T>(this List<T> list, ReadOnlySpan<T> source)
1212
{
13-
ArgumentNullException.ThrowIfNull(list);
13+
if (list is null)
14+
{
15+
throw new ArgumentNullException(nameof(list));
16+
}
1417

1518
if (!source.IsEmpty)
1619
{
@@ -24,4 +27,4 @@ public static void AddRange<T>(this List<T> list, ReadOnlySpan<T> source)
2427
}
2528
}
2629
}
27-
}
30+
}

Meziantou.Polyfill.Editor/M;System.Random.GetItems``1(System.ReadOnlySpan{``0},System.Int32).cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ partial class PolyfillExtensions
44
{
55
public static T[] GetItems<T>(this Random random, ReadOnlySpan<T> choices, int length)
66
{
7-
ArgumentNullException.ThrowIfNull(random);
8-
ArgumentOutOfRangeException.ThrowIfNegative(length);
7+
if (random is null)
8+
{
9+
throw new ArgumentNullException(nameof(random));
10+
}
11+
12+
if (length < 0)
13+
{
14+
throw new ArgumentOutOfRangeException(nameof(length), length, "must not be negative.");
15+
}
916

1017
if (choices.IsEmpty)
1118
{

Meziantou.Polyfill.Editor/M;System.Random.GetItems``1(System.ReadOnlySpan{``0},System.Span{``0}).cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ partial class PolyfillExtensions
44
{
55
public static void GetItems<T>(this Random random, ReadOnlySpan<T> choices, Span<T> destination)
66
{
7-
ArgumentNullException.ThrowIfNull(random);
7+
if (random is null)
8+
{
9+
throw new ArgumentNullException(nameof(random));
10+
}
811

912
if (choices.IsEmpty)
1013
{

Meziantou.Polyfill.Editor/M;System.Random.GetItems``1(``0[],System.Int32).cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ partial class PolyfillExtensions
55
{
66
public static T[] GetItems<T>(this Random random, T[] choices, int length)
77
{
8-
ArgumentNullException.ThrowIfNull(random);
9-
ArgumentNullException.ThrowIfNull(choices);
10-
ArgumentOutOfRangeException.ThrowIfNegative(length);
8+
if (random is null)
9+
{
10+
throw new ArgumentNullException(nameof(random));
11+
}
12+
13+
if (choices is null)
14+
{
15+
throw new ArgumentNullException(nameof(choices));
16+
}
17+
18+
if (length < 0)
19+
{
20+
throw new ArgumentOutOfRangeException(nameof(length), length, "must not be negative.");
21+
}
1122

1223
return GetItems(random, new ReadOnlySpan<T>(choices), length);
1324
}

Meziantou.Polyfill.Editor/M;System.Random.NextBytes(System.Span{System.Byte}).cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ partial class PolyfillExtensions
44
{
55
public static void NextBytes(this Random random, Span<byte> buffer)
66
{
7-
ArgumentNullException.ThrowIfNull(random);
7+
if (random is null)
8+
{
9+
throw new ArgumentNullException(nameof(random));
10+
}
811

912
byte[] array = new byte[buffer.Length];
1013
random.NextBytes(array);

Meziantou.Polyfill.Editor/M;System.Random.Shuffle``1(System.Span{``0}).cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ partial class PolyfillExtensions
44
{
55
public static void Shuffle<T>(this Random random, Span<T> values)
66
{
7-
ArgumentNullException.ThrowIfNull(random);
7+
if (random is null)
8+
{
9+
throw new ArgumentNullException(nameof(random));
10+
}
811

912
int n = values.Length;
1013
for (int i = 0; i < n - 1; i++)

Meziantou.Polyfill.Editor/M;System.Random.Shuffle``1(``0[]).cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ partial class PolyfillExtensions
55
{
66
public static void Shuffle<T>(this Random random, T[] values)
77
{
8-
ArgumentNullException.ThrowIfNull(random);
9-
ArgumentNullException.ThrowIfNull(values);
8+
if (random is null)
9+
{
10+
throw new ArgumentNullException(nameof(random));
11+
}
12+
13+
if (values is null)
14+
{
15+
throw new ArgumentNullException(nameof(values));
16+
}
1017

1118
Shuffle(random, values.AsSpan());
1219
}

Meziantou.Polyfill.Editor/M;System.Security.Cryptography.RandomNumberGenerator.Fill(System.Span{System.Byte}).cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ partial class PolyfillExtensions
22
{
33
public static void Fill(this System.Security.Cryptography.RandomNumberGenerator random, System.Span<byte> data)
44
{
5-
System.ArgumentNullException.ThrowIfNull(random);
5+
if (random is null)
6+
{
7+
throw new System.ArgumentNullException(nameof(random));
8+
}
69

710
if (data.IsEmpty)
811
return;

Meziantou.Polyfill.Editor/M;System.Security.Cryptography.RandomNumberGenerator.GetBytes(System.Int32).cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ partial class PolyfillExtensions
44
{
55
public static byte[] GetBytes(int count)
66
{
7-
System.ArgumentOutOfRangeException.ThrowIfNegative(count);
7+
if (count < 0)
8+
{
9+
throw new System.ArgumentOutOfRangeException(nameof(count), count, "must not be negative.");
10+
}
811

912
byte[] ret = new byte[count];
1013
using (var rng = System.Security.Cryptography.RandomNumberGenerator.Create())

Meziantou.Polyfill.Editor/M;System.Security.Cryptography.RandomNumberGenerator.GetItems``1(System.ReadOnlySpan{``0},System.Int32).cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ public static T[] GetItems<T>(System.ReadOnlySpan<T> choices, int length)
1010
if (choices.IsEmpty)
1111
throw new System.ArgumentException("choices cannot be empty.", nameof(choices));
1212

13-
System.ArgumentOutOfRangeException.ThrowIfNegative(length);
13+
if (length < 0)
14+
{
15+
throw new System.ArgumentOutOfRangeException(nameof(length), length, "must not be negative.");
16+
}
1417

1518
T[] result = new T[length];
1619
GetItems(choices, new Span<T>(result));

0 commit comments

Comments
 (0)