Hsu.Sg.Sync
2023.412.21-rc202346
See the version list below for details.
dotnet add package Hsu.Sg.Sync --version 2023.412.21-rc202346
NuGet\Install-Package Hsu.Sg.Sync -Version 2023.412.21-rc202346
<PackageReference Include="Hsu.Sg.Sync" Version="2023.412.21-rc202346"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Hsu.Sg.Sync --version 2023.412.21-rc202346
#r "nuget: Hsu.Sg.Sync, 2023.412.21-rc202346"
// Install Hsu.Sg.Sync as a Cake Addin #addin nuget:?package=Hsu.Sg.Sync&version=2023.412.21-rc202346&prerelease // Install Hsu.Sg.Sync as a Cake Tool #tool nuget:?package=Hsu.Sg.Sync&version=2023.412.21-rc202346&prerelease
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
ValueTask
in .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 |
---|---|---|
2024.101.8-rc175707 | 223 | 1/8/2024 |
2023.412.21 | 276 | 12/21/2023 |
2023.412.21-rc202346 | 185 | 12/21/2023 |
2023.412.17 | 200 | 12/17/2023 |
2023.412.17-rc170547 | 162 | 12/17/2023 |
2023.412.14.1 | 225 | 12/14/2023 |
2023.412.12 | 143 | 12/12/2023 |
2023.411.27 | 235 | 11/27/2023 |
2023.410.20.1 | 267 | 10/20/2023 |
2023.410.20 | 258 | 10/20/2023 |
2023.410.19-pre1 | 196 | 10/18/2023 |
2023.410.18 | 226 | 10/18/2023 |
2023.410.16 | 268 | 10/16/2023 |