Skip to content
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
23 changes: 10 additions & 13 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,38 +205,35 @@ Currently, **PolyShim** recognizes the following packages:
> [!IMPORTANT]
> Ensure your compatibility packages are referenced in their latest stable versions, so that their provided API surface matches what **PolyShim** expects.

For example, adding a reference to the `Microsoft.Bcl.AsyncInterfaces` package will enable **PolyShim**'s polyfills that work with `IAsyncEnumerable<T>`, such as `Task.WhenEach(...)`:
For example, adding a reference to the `Microsoft.Bcl.Async` package on .NET Framework 4.0 will enable **PolyShim**'s `ValueTask` and `IAsyncEnumerable<T>` polyfills:

```xml
<Project>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net40</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PolyShim" Version="..." />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="..." />
<PackageReference Include="Microsoft.Bcl.Async" Version="..." />
</ItemGroup>

</Project>
```

```csharp
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;

var tasks = Enumerable.Range(1, 10).Select(async i =>
// Microsoft.Bcl.Async is referenced, so these polyfills are enabled
static async ValueTask<int> SumAsync(IAsyncEnumerable<int> source)
{
await Task.Delay(Random.Shared.Next(1000));
return i * i;
});
var sum = 0;
await foreach (var value in source)
sum += value;

// Microsoft.Bcl.AsyncInterfaces is referenced, so this polyfill is enabled
await foreach (var completedTask in Task.WhenEach(tasks))
{
Console.WriteLine(await completedTask);
return sum;
}
```

Expand Down
Loading