Skip to main content

Hsu.Sg.FluentMember by Net Hsu

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: Hsu.Sg.FluentMember

a fluent member source generator.

Author: Net Hsu

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

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

Adding builder pattern to classes

How to use

Example ( source csproj, source files )

This is the CSharp Project that references Hsu.Sg.FluentMember

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Hsu.Sg.FluentMember" Version="2024.101.8-rc175707">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>



</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>

using System;

namespace Hsu.Sg.FluentMember
{
/// <summary>
/// The flag to generate member set method.
/// </summary>
[AttributeUsage(
AttributeTargets.Struct |
AttributeTargets.Class,
AllowMultiple = false,
Inherited = false)]
internal sealed class FluentMemberAttribute : Attribute
{

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

/// <summary>
/// The internal member are generated.
/// </summary>
public bool Internal { get; set; }

/// <summary>
/// The private member are generated.
/// </summary>
public bool Private { get; set; }

/// <summary>
/// Only [FluentMemberGen] member are generated.
/// </summary>
public bool Only { get; set; }

/// <summary>
/// The prefix of member name.
/// </summary>
/// <remarks>default is `With`</remarks>
public string Prefix { get; set; } = string.Empty;
}

[AttributeUsage(AttributeTargets.Field |
AttributeTargets.Property |
AttributeTargets.Event,
AllowMultiple = false,
Inherited = false)]
internal sealed class FluentMemberGenAttribute : Attribute
{
/// <summary>
/// Ignore member.
/// </summary>
public bool Ignore { get; set; }

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

/// <summary>
/// The prefix of member name.
/// </summary>
/// <remarks>default is `With`</remarks>
public string Prefix { get; set; } = string.Empty;

/// <summary>
/// The modifier of member
/// </summary>
/// <remarks>default is <see cref="Accessibility.Inherit"/></remarks>
public Accessibility Modifier { get; set; } = Accessibility.Inherit;
}

/// <summary>
/// The accessibility for fluent member set method.
/// </summary>
//[System.DefaultValue(Inherit)]
internal enum Accessibility
{
/// <summary>
/// Inherit from the member.
/// </summary>
Inherit,
/// <summary>
/// Is public access.
/// </summary>
Public,
/// <summary>
/// Is internal access.
/// </summary>
Internal,
/// <summary>
/// Is protected access.
/// </summary>
Protected,
/// <summary>
/// Is private access.
/// </summary>
Private
}

/// <summary>
/// The event assignment
/// </summary>
//[System.DefaultValue(Add)]
public enum EventAssignable
{
/// <summary>
/// To add the event
/// </summary>
Add,
/// <summary>
/// To remove the event
/// </summary>
Remove,
/// <summary>
/// To set the event
/// </summary>
Assign
}
}

Usefull

Download Example (.NET C# )

Share Hsu.Sg.FluentMember

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Hsu.Sg.FluentMember

In the same category (Builder) - 3 other generators

Architect.DomainModeling

BuilderGenerator

Fluentify