Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<DefineConstants>$(DefineConstants);SUPPORTS_AUTHORIZATION_MIDDLEWARE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_BCL_ASYNC_ENUMERABLE</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_BULK_DBSET_OPERATIONS</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_CHUNK_LINQ_EXTENSION</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_DBSET_VALUETASK_FINDASYNC</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENDPOINT_ROUTING</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_ENVIRONMENT_PROCESS_PATH</DefineConstants>
Expand Down
18 changes: 9 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
Note: OpenIddict uses Meziantou.Polyfill to dynamically generate polyfills for types that are not available
on some of the targeted TFMs (e.g Index, Range or nullable attributes on .NET Framework/.NET Standard).
-->
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.101" />
<GlobalPackageReference Include="Meziantou.Polyfill" Condition=" '$(IncludePolyfills)' != 'false' " Version="1.0.104" />
</ItemGroup>

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

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

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

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

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

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

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

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

</Project>
126 changes: 0 additions & 126 deletions shared/OpenIddict.Extensions/OpenIddictPolyfills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* the license and the contributors participating to this project.
*/

using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography.X509Certificates;
Expand All @@ -17,58 +15,6 @@ namespace OpenIddict.Extensions;
/// </summary>
internal static class OpenIddictPolyfills
{
extension(ArgumentOutOfRangeException)
{
/// <summary>Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is negative.</summary>
/// <param name="value">The argument to validate as non-negative.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
public static void ThrowIfNegative<T>(T value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
where T : struct, IComparable<T>
{
switch (value)
{
case byte or ushort or uint or ulong or char:
return;
case sbyte n:
if (n < 0)
ThrowArgumentOutOfRangeException(paramName, value);
return;
case short n:
if (n < 0)
ThrowArgumentOutOfRangeException(paramName, value);
return;
case int n:
if (n < 0)
ThrowArgumentOutOfRangeException(paramName, value);
return;
case long n:
if (n < 0L)
ThrowArgumentOutOfRangeException(paramName, value);
return;

case float n:
if (n < 0F)
ThrowArgumentOutOfRangeException(paramName, value);
return;
case double n:
if (n < 0D)
ThrowArgumentOutOfRangeException(paramName, value);
return;
case decimal n:
if (n < 0M)
ThrowArgumentOutOfRangeException(paramName, value);
return;
default:
throw new InvalidOperationException($"Invalid type '{typeof(T).AssemblyQualifiedName}' for {paramName}.");
}

static void ThrowArgumentOutOfRangeException(string? paramName, object value)
{
throw new ArgumentOutOfRangeException(paramName, value, $"{paramName} ('{value}') must not be negative.");
}
}
}

extension(Convert)
{
#if !SUPPORTS_HEXADECIMAL_STRING_CONVERSION
Expand Down Expand Up @@ -98,78 +44,6 @@ public static byte[] FromHexString(string s)
#endif
}

extension<TSource>(IEnumerable<TSource> source)
{
#if !SUPPORTS_CHUNK_LINQ_EXTENSION
/// <summary>
/// Split the elements of a sequence into chunks of size at most <paramref name="size"/>.
/// </summary>
/// <remarks>
/// Every chunk except the last will be of size <paramref name="size"/>.
/// The last chunk will contain the remaining elements and may be of a smaller size.
/// </remarks>
/// <param name="size">Maximum size of each chunk.</param>
/// <returns>
/// An <see cref="IEnumerable{T}"/> that contains the elements of the input
/// sequence split into chunks of size <paramref name="size"/>.
/// </returns>
public IEnumerable<TSource[]> Chunk(int size)
{
// Note: this polyfill was directly copied from .NET's source code:
// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Linq/src/System/Linq/Chunk.cs.

using IEnumerator<TSource> enumerator = source.GetEnumerator();

if (enumerator.MoveNext())
{
var count = Math.Min(size, 4);
int index;

do
{
var array = new TSource[count];

array[0] = enumerator.Current;
index = 1;

if (size != array.Length)
{
for (; index < size && enumerator.MoveNext(); index++)
{
if (index >= array.Length)
{
count = (int) Math.Min((uint) size, 2 * (uint) array.Length);
Array.Resize(ref array, count);
}

array[index] = enumerator.Current;
}
}

else
{
var local = array;
Debug.Assert(local.Length == size);
for (; (uint) index < (uint) local.Length && enumerator.MoveNext(); index++)
{
local[index] = enumerator.Current;
}
}

if (index != array.Length)
{
Array.Resize(ref array, index);
}

yield return array;
}

while (index >= size && enumerator.MoveNext());
}
}
#endif
}

extension(OperatingSystem)
{
#if !SUPPORTS_OPERATING_SYSTEM_VERSIONS_COMPARISON
Expand Down
Loading