Hsu.Sg.Sync 2023.412.21-rc202346

This is a prerelease version of Hsu.Sg.Sync.
There is a newer version of this package available.
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                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hsu.Sg.Sync" Version="2023.412.21-rc202346">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hsu.Sg.Sync --version 2023.412.21-rc202346                
#r "nuget: Hsu.Sg.Sync, 2023.412.21-rc202346"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Nito.AsyncEx

Generate a synchronous method from an asynchronous method.

Package Version

Name Source Stable Preview
Hsu.Sg.Sync Nuget NuGet NuGet
Hsu.Sg.Sync MyGet MyGet 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 package System.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

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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