Zomp.SyncMethodGenerator
0.1.30-alpha
See the version list below for details.
dotnet add package Zomp.SyncMethodGenerator --version 0.1.30-alpha
NuGet\Install-Package Zomp.SyncMethodGenerator -Version 0.1.30-alpha
<PackageReference Include="Zomp.SyncMethodGenerator" Version="0.1.30-alpha" />
<PackageVersion Include="Zomp.SyncMethodGenerator" Version="0.1.30-alpha" />
<PackageReference Include="Zomp.SyncMethodGenerator" />
paket add Zomp.SyncMethodGenerator --version 0.1.30-alpha
#r "nuget: Zomp.SyncMethodGenerator, 0.1.30-alpha"
#:package Zomp.SyncMethodGenerator@0.1.30-alpha
#addin nuget:?package=Zomp.SyncMethodGenerator&version=0.1.30-alpha&prerelease
#tool nuget:?package=Zomp.SyncMethodGenerator&version=0.1.30-alpha&prerelease
Sync Method Generator
This .NET source generator produces a sync method from an async one.
Use cases
- A library which exposes both sync and async version of a method
- An application has to process two kinds of data in the same way:
- Large data from I/O which cannot be stored in memory before processing: Original async method
- Small sample of data in memory, usually a sample of the larger data: Generated sync method
How it works
Add CreateSyncVersionAttribute to your async method in your partial class
[Zomp.SyncMethodGenerator.CreateSyncVersion]
static async Task WriteAsync(ReadOnlyMemory<byte> buffer, Stream stream,
CancellationToken ct)
=> await stream.WriteAsync(buffer, ct).ConfigureAwait(true);
And it will generate a sync version of the method:
static void Write(ReadOnlySpan<byte> buffer, Stream stream)
=> stream.Write(buffer);
A list of changes applied to the new synchronized method:
Remove async modifier
Remove await from methods as well as
foreachstatementChange types
From To Task or ValueTask void Task<T> or ValueTask<T> T IAsyncEnumerable<T> IEnumerable<T> IAsyncEnumerator<T> IEnumerator<T> Memory<T> Span<T> ReadOnlyMemory<T> ReadOnlySpan<T> Remove parameters
Invocation changes
- Remove ConfigureAwait
- Remove WithCancellation
- Remove
Asyncsuffix from method calls (e.g. MoveNextAsync becomes MoveNext) - Remove CancellationToken parameter
- Remove IProgress<T>.Report(T) call
- Remove Memory<T>.Span property
Remove
CreateSyncVersionAttributeUpdate XML documentation
Installation
To add the library use:
dotnet add package Zomp.SyncMethodGenerator
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (4)
Showing the top 4 popular GitHub repositories that depend on Zomp.SyncMethodGenerator:
| Repository | Stars |
|---|---|
|
FluentValidation/FluentValidation
A popular .NET validation library for building strongly-typed validation rules.
|
|
|
mini-software/MiniExcel
Lightweight, fast and simple cross-platform .NET processing tool for importing and exporting spreadsheet documents
|
|
|
Zeugma440/atldotnet
Fully managed, portable and easy-to-use C# library to read and edit audio data and metadata (tags) from various audio formats, playlists and CUE sheets
|
|
|
BigBang1112/gbx-net
General purpose library for Gbx files - data from Nadeo games like Trackmania or Shootmania, written in C#/.NET. It supports high performance serialization and deserialization of 400+ Gbx classes.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.42 | 1,194 | 7/28/2026 |
| 2.0.41 | 111 | 7/28/2026 |
| 2.0.40 | 136 | 7/28/2026 |
| 2.0.38 | 105 | 7/28/2026 |
| 2.0.35 | 106 | 7/27/2026 |
| 2.0.33 | 113 | 7/27/2026 |
| 2.0.32 | 150 | 7/27/2026 |
| 2.0.20 | 112 | 7/27/2026 |
| 2.0.16 | 1,449 | 6/26/2026 |
| 2.0.15 | 240 | 6/25/2026 |
| 2.0.13 | 2,219 | 4/29/2026 |
| 2.0.8 | 2,086 | 3/1/2026 |
| 2.0.7 | 12,537 | 12/24/2025 |
| 2.0.5 | 494 | 12/15/2025 |
| 2.0.4 | 392 | 11/27/2025 |
| 2.0.3 | 285 | 11/27/2025 |
| 2.0.2 | 262 | 11/24/2025 |
| 2.0.1 | 280 | 11/24/2025 |
| 1.6.17 | 1,777 | 7/28/2025 |
| 0.1.30-alpha | 438 | 11/21/2022 |