Hsu.Sg.Sync 2024.101.8-rc175707

This is a prerelease version of Hsu.Sg.Sync.
dotnet add package Hsu.Sg.Sync --version 2024.101.8-rc175707
                    
NuGet\Install-Package Hsu.Sg.Sync -Version 2024.101.8-rc175707
                    
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="2024.101.8-rc175707">
  <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.
<PackageVersion Include="Hsu.Sg.Sync" Version="2024.101.8-rc175707" />
                    
Directory.Packages.props
<PackageReference Include="Hsu.Sg.Sync">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hsu.Sg.Sync --version 2024.101.8-rc175707
                    
#r "nuget: Hsu.Sg.Sync, 2024.101.8-rc175707"
                    
#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.
#:package Hsu.Sg.Sync@2024.101.8-rc175707
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hsu.Sg.Sync&version=2024.101.8-rc175707&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Hsu.Sg.Sync&version=2024.101.8-rc175707&prerelease
                    
Install as a Cake Tool

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 262 1/8/2024
2023.412.21 340 12/21/2023
2023.412.21-rc202346 227 12/21/2023
2023.412.17 250 12/17/2023
2023.412.17-rc170547 200 12/17/2023
2023.412.14.1 280 12/14/2023
2023.412.12 182 12/12/2023
2023.411.27 263 11/27/2023
2023.410.20.1 314 10/20/2023
2023.410.20 292 10/20/2023
2023.410.19-pre1 238 10/18/2023
2023.410.18 272 10/18/2023
2023.410.16 315 10/16/2023