Skip to content

Commit f362e68

Browse files
authored
Detect Microsoft.Bcl.Memory and disable related polyfills (#21)
1 parent 6c18a87 commit f362e68

File tree

6 files changed

+12
-3
lines changed

6 files changed

+12
-3
lines changed

PolyShim/NetCore30/Index.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The following comment is required to instruct analyzers to skip this file
22
// <auto-generated/>
33

4-
#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER)
4+
#if !FEATURE_INDEXRANGE
55
#nullable enable
66
// ReSharper disable RedundantUsingDirective
77
// ReSharper disable CheckNamespace

PolyShim/NetCore30/Range.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The following comment is required to instruct analyzers to skip this file
22
// <auto-generated/>
33

4-
#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER)
4+
#if !FEATURE_INDEXRANGE
55
#nullable enable
66
// ReSharper disable RedundantUsingDirective
77
// ReSharper disable CheckNamespace

PolyShim/NetCore30/RuntimeHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// The following comment is required to instruct analyzers to skip this file
22
// <auto-generated/>
33

4-
#if (NETCOREAPP && !NETCOREAPP3_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER)
4+
#if !FEATURE_INDEXRANGE
55
#nullable enable
66
// ReSharper disable RedundantUsingDirective
77
// ReSharper disable CheckNamespace

PolyShim/PolyShim.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard' AND $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '2.0'))" />
5656
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '4.6.1'))" />
5757
<PackageReference Include="Microsoft.Bcl.Async" Version="1.0.168" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.0'))" />
58+
<PackageReference Include="Microsoft.Bcl.Memory" Version="9.0.1" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.6.2'))" />
5859
<PackageReference Include="Microsoft.Net.Http" Version="2.2.29" PrivateAssets="all" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '4.0'))" />
5960
</ItemGroup>
6061

PolyShim/PolyShim.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
<FeatureHttpClient Condition="$(IsNetCoreApp) AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '1.0'))">true</FeatureHttpClient>
4040
<DefineConstants Condition="$(FeatureHttpClient)">$(DefineConstants);FEATURE_HTTPCLIENT</DefineConstants>
4141

42+
<FeatureIndexRange>false</FeatureIndexRange>
43+
<FeatureIndexRange Condition="@(Reference->AnyHaveMetadataValue('Identity', 'Microsoft.Bcl.Memory'))">true</FeatureIndexRange>
44+
<FeatureIndexRange Condition="@(PackageDependencies->AnyHaveMetadataValue('Identity', 'Microsoft.Bcl.Memory'))">true</FeatureIndexRange>
45+
<FeatureIndexRange Condition="$(IsNetStandard) AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '2.1'))">true</FeatureIndexRange>
46+
<FeatureIndexRange Condition="$(IsNetCoreApp) AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '3.0'))">true</FeatureIndexRange>
47+
<DefineConstants Condition="$(FeatureIndexRange)">$(DefineConstants);FEATURE_INDEXRANGE</DefineConstants>
48+
4249
<FeatureManagement>false</FeatureManagement>
4350
<FeatureManagement Condition="@(Reference->AnyHaveMetadataValue('Identity', 'System.Management'))">true</FeatureManagement>
4451
<FeatureManagement Condition="@(PackageDependencies->AnyHaveMetadataValue('Identity', 'System.Management'))">true</FeatureManagement>

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Currently, **PolyShim** has integration with the following packages:
132132
- [`Microsoft.Bcl.Async`](https://nuget.org/packages/Microsoft.Bcl.Async)`Task`, `Task<T>`, etc (wider support than the `System.*` variant).
133133
- [`Microsoft.Bcl.AsyncInterfaces`](https://nuget.org/packages/Microsoft.Bcl.AsyncInterfaces)`IAsyncEnumerable<T>`, `IAsyncDisposable`, etc.
134134
- [`Microsoft.Bcl.HashCode`](https://nuget.org/packages/Microsoft.Bcl.HashCode)`HashCode`, etc.
135+
- [`Microsoft.Bcl.Memory`](https://nuget.org/packages/Microsoft.Bcl.Memory)`Index`, `Range`, etc.
135136
- [`Microsoft.Net.Http`](https://nuget.org/packages/Microsoft.Net.Http)`HttpClient`, `HttpContent`, etc (wider support than the `System.*` variant).
136137

137138
For example, adding a reference to the `System.Memory` package will enable **PolyShim**'s polyfills that offer `Span<T>` and `Memory<T>`-based method overloads on various built-in types, such as `Stream`:

0 commit comments

Comments
 (0)