Hsu.Sg.Sync
2026.101.6
dotnet add package Hsu.Sg.Sync --version 2026.101.6
NuGet\Install-Package Hsu.Sg.Sync -Version 2026.101.6
<PackageReference Include="Hsu.Sg.Sync" Version="2026.101.6"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Hsu.Sg.Sync" Version="2026.101.6" />
<PackageReference Include="Hsu.Sg.Sync"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Hsu.Sg.Sync --version 2026.101.6
#r "nuget: Hsu.Sg.Sync, 2026.101.6"
#:package Hsu.Sg.Sync@2026.101.6
#addin nuget:?package=Hsu.Sg.Sync&version=2026.101.6
#tool nuget:?package=Hsu.Sg.Sync&version=2026.101.6
Hsu.Sg.Sync
Generate a synchronous method from an asynchronous method.
Package Version
| Name | Source | Stable | Preview |
|---|---|---|---|
| Hsu.Sg.Sync | Nuget | ||
| Hsu.Sg.Sync | MyGet |
Usages
Install
- Hsu.Sg.Sync
- Nito.AsyncEx.Context
- System.Threading.Tasks.Extensions
You can install the packages from nuget.
<PackageReference Include="Hsu.Sg.Sync" Version="2023.412.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
If you want to use
ValueTaskin .net framework, you should install the packageSystem.Threading.Tasks.Extensions.*
Attributes
Add the Sync attribute and partial keyword to the object that has asynchronous method.
[Sync]
public partial class ClassSamplePartial
{
public Task PartialTaskAsync()
{
return Task.CompletedTask;
}
}
If you want to specify an asynchronous method to generate a synchronous method, you just need to set [Sync(Only = true)] and add [SyncGen] attribute to the method.
[Sync(Only = true)]
public partial class ClassSampleSyncOnly
{
[SyncGen]
public static ValueTask<Dictionary<string, object>> StaticValueTaskDictionaryAsync()
{
return new ValueTask<Dictionary<string, object>>(new Dictionary<string, object>());
}
}
If you want to ignore generate a synchronous method, you just need to add [SyncGen(Ignore=true)] attribute to the method.
[Sync(Only = true)]
public partial class ClassSampleSyncOnly
{
[SyncGen(Ignore = true)]
public Task AwaitAsync(int index, string name, CancellationToken token = default)
{
return Task.CompletedTask;
}
}
If you want to specify an identifier with generated a synchronous method, you just need to add [SyncGen(Identifier = "AwaitRename")] attribute to the method.
[Sync(Only = true)]
public partial class ClassSampleSyncOnly
{
[SyncGen(Identifier = "AwaitRename")]
public Task AwaitAsync(int index, string name, CancellationToken token = default)
{
return Task.CompletedTask;
}
}
If you just want to generate a abstract or interface synchronous method, you need to add [Sync(Definable =true)] attribute to the abstract class or interface.
[Sync(Definable =true)]
public abstract partial class DefinableClass
{
public abstract Task AwaitAsync(int index, string name, CancellationToken token);
}
[Sync(Definable =true)]
public abstract partial record DefinableRecord
{
public abstract Task AwaitAsync(int index, string name, CancellationToken token);
}
References
License
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Nito.AsyncEx.Context (>= 5.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.101.6 | 86 | 1/6/2026 |
| 2026.101.5 | 86 | 1/5/2026 |
| 2026.101.5-rc173948 | 92 | 1/5/2026 |
| 2026.101.5-rc145021 | 86 | 1/5/2026 |
| 2024.101.8-rc175707 | 315 | 1/8/2024 |
| 2023.412.21 | 411 | 12/21/2023 |
| 2023.412.21-rc202346 | 270 | 12/21/2023 |
| 2023.412.17 | 296 | 12/17/2023 |
| 2023.412.17-rc170547 | 254 | 12/17/2023 |
| 2023.412.14.1 | 342 | 12/14/2023 |
| 2023.412.12 | 211 | 12/12/2023 |
| 2023.411.27 | 307 | 11/27/2023 |
| 2023.410.20.1 | 377 | 10/20/2023 |
| 2023.410.20 | 323 | 10/20/2023 |
| 2023.410.19-pre1 | 277 | 10/18/2023 |
| 2023.410.18 | 327 | 10/18/2023 |
| 2023.410.16 | 367 | 10/16/2023 |