Skip to main content

HsuSgSync by Net Hsu

NuGet / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: HsuSgSync

an async method to sync source generator.

Author: Net Hsu

NuGet: https://www.nuget.org/packages/Hsu.Sg.Sync/

You can find more details at https://github.com/hsu-net/source-generators

Source: https://github.com/hsu-net/source-generators

Original Readme

note

Hsu.Sg

dev preview main nuke build

.NET source generators

Package Version

NameSourceStablePreview
Hsu.Sg.SyncNugetNuGetNuGet
Hsu.Sg.SyncMyGetMyGetMyGet
Hsu.Sg.ProxyNugetNuGetNuGet
Hsu.Sg.ProxyMyGetMyGetMyGet
Hsu.Sg.FluentMemberNugetNuGetNuGet
Hsu.Sg.FluentMemberMyGetMyGetMyGet

Package Features

Hsu.Sg.Sync

Generate a synchronous method from an asynchronous method.

Usages see README

Hsu.Sg.Proxy

Generate a proxy object from a struct or class or interface.

Usages see README

Hsu.Sg.FluentMember

Generate a fluent method from a struct or class.

Usages see README

References

License

MIT

About

note

Generate code for async to sync methods

How to use

Example (source csproj, source files)

This is the CSharp Project that references HsuSgSync

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hsu.Sg.Sync" Version="2023.412.21" OutputItemType="Analyzer" >
</PackageReference>
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>

using System;

namespace Hsu.Sg.Sync
{
/// <summary>
/// The flag to generate async method to sync method.
/// </summary>
[AttributeUsage(
System.AttributeTargets.Interface |
System.AttributeTargets.Struct |
System.AttributeTargets.Class,
AllowMultiple = false,
Inherited = false)]
internal sealed class SyncAttribute : Attribute
{
/// <summary>
/// Only <c>interface</c> or <c>abstract</c> async methods are generated.
/// </summary>
public bool Definable { get; set; }

/// <summary>
/// The public async methods are generated.
/// </summary>
public bool Public { get; set; } = true;

/// <summary>
/// The internal async methods are generated.
/// </summary>
public bool Internal { get; set; } = true;

/// <summary>
/// The private async methods are generated.
/// </summary>
public bool Private { get; set; } = true;

/// <summary>
/// Only [SyncGen] async methods are generated.
/// </summary>
public bool Only { get; set; } = false;

/// <summary>
/// The suffix of sync method name when not end with Async.
/// </summary>
/// <remarks>default is `Sync`</remarks>
public string Suffix { get; set; } = string.Empty;

/// <summary>
/// Whether generate attributes.
/// </summary>
public bool Attribute { get; set; } = false;

/// <summary>
/// To generate with attributes
/// </summary>
public string[] AttributeIncludes { get; set; } = null;

/// <summary>
/// To generate without attributes
/// </summary>
public string[] AttributeExcludes { get; set; } = null;

public SyncAttribute()
{
Public = true;
Internal = true;
Private = true;
Only = false;
Suffix = string.Empty;
}
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
internal sealed class SyncGenAttribute : Attribute
{
/// <summary>
/// Ignore to generate sync methods.
/// </summary>
public bool Ignore { get; set; } = false;

/// <summary>
/// The specific name of sync method.
/// </summary>
public string Identifier { get; set; } = string.Empty;

/// <summary>
/// The suffix of sync method name when not end with Async.
/// </summary>
/// <remarks>default is `Sync`</remarks>
public string Suffix { get; set; } = string.Empty;
}
}

Useful

Download Example (.NET C#)

Share HsuSgSync

https://ignatandrei.github.io/RSCG_Examples/v2/docs/HsuSgSync

aaa

Category "Async" has the following generators:

1 AsyncIt

2 HsuSgSync

See category

Async