Hsu.Sg.Sync
2024.101.8-rc175707
dotnet add package Hsu.Sg.Sync --version 2024.101.8-rc175707
NuGet\Install-Package Hsu.Sg.Sync -Version 2024.101.8-rc175707
<PackageReference Include="Hsu.Sg.Sync" Version="2024.101.8-rc175707"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Hsu.Sg.Sync --version 2024.101.8-rc175707
#r "nuget: Hsu.Sg.Sync, 2024.101.8-rc175707"
// Install Hsu.Sg.Sync as a Cake Addin #addin nuget:?package=Hsu.Sg.Sync&version=2024.101.8-rc175707&prerelease // Install Hsu.Sg.Sync as a Cake Tool #tool nuget:?package=Hsu.Sg.Sync&version=2024.101.8-rc175707&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 | 226 | 1/8/2024 |
2023.412.21 | 279 | 12/21/2023 |
2023.412.21-rc202346 | 190 | 12/21/2023 |
2023.412.17 | 203 | 12/17/2023 |
2023.412.17-rc170547 | 165 | 12/17/2023 |
2023.412.14.1 | 228 | 12/14/2023 |
2023.412.12 | 146 | 12/12/2023 |
2023.411.27 | 238 | 11/27/2023 |
2023.410.20.1 | 270 | 10/20/2023 |
2023.410.20 | 263 | 10/20/2023 |
2023.410.19-pre1 | 199 | 10/18/2023 |
2023.410.18 | 229 | 10/18/2023 |
2023.410.16 | 271 | 10/16/2023 |