Skip to content

Commit df3d0a1

Browse files
committed
Bump Meziantou.Polyfill to 1.0.104 and use the built-in Chunk()/ThrowIfNegative() polyfills
1 parent 95e74ae commit df3d0a1

File tree

3 files changed

+9
-136
lines changed

3 files changed

+9
-136
lines changed

Directory.Build.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHORIZATION_MIDDLEWARE</DefineConstants>
6060
<DefineConstants>$(DefineConstants);SUPPORTS_BCL_ASYNC_ENUMERABLE</DefineConstants>
6161
<DefineConstants>$(DefineConstants);SUPPORTS_BULK_DBSET_OPERATIONS</DefineConstants>
62-
<DefineConstants>$(DefineConstants);SUPPORTS_CHUNK_LINQ_EXTENSION</DefineConstants>
6362
<DefineConstants>$(DefineConstants);SUPPORTS_DBSET_VALUETASK_FINDASYNC</DefineConstants>
6463
<DefineConstants>$(DefineConstants);SUPPORTS_ENDPOINT_ROUTING</DefineConstants>
6564
<DefineConstants>$(DefineConstants);SUPPORTS_ENVIRONMENT_PROCESS_PATH</DefineConstants>

Directory.Packages.props

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
5454
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
5555
-->
56-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
56+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
5757
</ItemGroup>
5858

5959
<!--
@@ -110,7 +110,7 @@
110110
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
111111
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
112112
-->
113-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
113+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
114114
</ItemGroup>
115115

116116
<!--
@@ -202,7 +202,7 @@
202202
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
203203
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
204204
-->
205-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
205+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
206206
</ItemGroup>
207207

208208
<!--
@@ -249,7 +249,7 @@
249249
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
250250
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
251251
-->
252-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
252+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
253253
</ItemGroup>
254254

255255
<!--
@@ -295,7 +295,7 @@
295295
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
296296
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
297297
-->
298-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
298+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
299299
</ItemGroup>
300300

301301
<!--
@@ -354,7 +354,7 @@
354354
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
355355
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
356356
-->
357-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
357+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
358358
</ItemGroup>
359359

360360
<!--
@@ -405,7 +405,7 @@
405405
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
406406
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
407407
-->
408-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
408+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
409409
</ItemGroup>
410410

411411
<!--
@@ -446,7 +446,7 @@
446446
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
447447
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
448448
-->
449-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
449+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
450450
</ItemGroup>
451451

452452
<!--
@@ -468,7 +468,7 @@
468468
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
469469
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
470470
-->
471-
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
471+
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
472472
</ItemGroup>
473473

474474
</Project>

shared/OpenIddict.Extensions/OpenIddictPolyfills.cs

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* the license and the contributors participating to this project.
55
*/
66

7-
using System.Diagnostics;
8-
using System.Runtime.CompilerServices;
97
using System.Runtime.InteropServices;
108
using System.Runtime.Versioning;
119
using System.Security.Cryptography.X509Certificates;
@@ -17,58 +15,6 @@ namespace OpenIddict.Extensions;
1715
/// </summary>
1816
internal static class OpenIddictPolyfills
1917
{
20-
extension(ArgumentOutOfRangeException)
21-
{
22-
/// <summary>Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is negative.</summary>
23-
/// <param name="value">The argument to validate as non-negative.</param>
24-
/// <param name="paramName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
25-
public static void ThrowIfNegative<T>(T value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
26-
where T : struct, IComparable<T>
27-
{
28-
switch (value)
29-
{
30-
case byte or ushort or uint or ulong or char:
31-
return;
32-
case sbyte n:
33-
if (n < 0)
34-
ThrowArgumentOutOfRangeException(paramName, value);
35-
return;
36-
case short n:
37-
if (n < 0)
38-
ThrowArgumentOutOfRangeException(paramName, value);
39-
return;
40-
case int n:
41-
if (n < 0)
42-
ThrowArgumentOutOfRangeException(paramName, value);
43-
return;
44-
case long n:
45-
if (n < 0L)
46-
ThrowArgumentOutOfRangeException(paramName, value);
47-
return;
48-
49-
case float n:
50-
if (n < 0F)
51-
ThrowArgumentOutOfRangeException(paramName, value);
52-
return;
53-
case double n:
54-
if (n < 0D)
55-
ThrowArgumentOutOfRangeException(paramName, value);
56-
return;
57-
case decimal n:
58-
if (n < 0M)
59-
ThrowArgumentOutOfRangeException(paramName, value);
60-
return;
61-
default:
62-
throw new InvalidOperationException($"Invalid type '{typeof(T).AssemblyQualifiedName}' for {paramName}.");
63-
}
64-
65-
static void ThrowArgumentOutOfRangeException(string? paramName, object value)
66-
{
67-
throw new ArgumentOutOfRangeException(paramName, value, $"{paramName} ('{value}') must not be negative.");
68-
}
69-
}
70-
}
71-
7218
extension(Convert)
7319
{
7420
#if !SUPPORTS_HEXADECIMAL_STRING_CONVERSION
@@ -98,78 +44,6 @@ public static byte[] FromHexString(string s)
9844
#endif
9945
}
10046

101-
extension<TSource>(IEnumerable<TSource> source)
102-
{
103-
#if !SUPPORTS_CHUNK_LINQ_EXTENSION
104-
/// <summary>
105-
/// Split the elements of a sequence into chunks of size at most <paramref name="size"/>.
106-
/// </summary>
107-
/// <remarks>
108-
/// Every chunk except the last will be of size <paramref name="size"/>.
109-
/// The last chunk will contain the remaining elements and may be of a smaller size.
110-
/// </remarks>
111-
/// <param name="size">Maximum size of each chunk.</param>
112-
/// <returns>
113-
/// An <see cref="IEnumerable{T}"/> that contains the elements of the input
114-
/// sequence split into chunks of size <paramref name="size"/>.
115-
/// </returns>
116-
public IEnumerable<TSource[]> Chunk(int size)
117-
{
118-
// Note: this polyfill was directly copied from .NET's source code:
119-
// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Linq/src/System/Linq/Chunk.cs.
120-
121-
using IEnumerator<TSource> enumerator = source.GetEnumerator();
122-
123-
if (enumerator.MoveNext())
124-
{
125-
var count = Math.Min(size, 4);
126-
int index;
127-
128-
do
129-
{
130-
var array = new TSource[count];
131-
132-
array[0] = enumerator.Current;
133-
index = 1;
134-
135-
if (size != array.Length)
136-
{
137-
for (; index < size && enumerator.MoveNext(); index++)
138-
{
139-
if (index >= array.Length)
140-
{
141-
count = (int) Math.Min((uint) size, 2 * (uint) array.Length);
142-
Array.Resize(ref array, count);
143-
}
144-
145-
array[index] = enumerator.Current;
146-
}
147-
}
148-
149-
else
150-
{
151-
var local = array;
152-
Debug.Assert(local.Length == size);
153-
for (; (uint) index < (uint) local.Length && enumerator.MoveNext(); index++)
154-
{
155-
local[index] = enumerator.Current;
156-
}
157-
}
158-
159-
if (index != array.Length)
160-
{
161-
Array.Resize(ref array, index);
162-
}
163-
164-
yield return array;
165-
}
166-
167-
while (index >= size && enumerator.MoveNext());
168-
}
169-
}
170-
#endif
171-
}
172-
17347
extension(OperatingSystem)
17448
{
17549
#if !SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON

0 commit comments

Comments
 (0)