RSCG – Fluentify
RSCG – Fluentify
name | Fluentify |
nuget | https://www.nuget.org/packages/Fluentify/ |
link | https://github.com/MooVC/fluentify |
author | Paul Martins |
Generate fluent builder
This is how you can use Fluentify .
The code that you start with is
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 | < 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 = "Fluentify" Version = "1.1.0" > < PrivateAssets >all</ PrivateAssets > < IncludeAssets >runtime; build; native; contentfiles; analyzers; buildtransitive</ IncludeAssets > </ PackageReference > </ ItemGroup > </ Project > |
The code that you will use is
1 2 3 4 5 6 | using Builder; var pOld = new Person(); pOld= pOld.WithFirstName( "Andrei" ).WithLastName( "Ignat" ).WithMiddleName( "G" ); System.Console.WriteLine(pOld.FullName()); |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 | namespace Builder; [Fluentify.Fluentify] public partial class Person { public string FirstName { get ; init; } public string ? MiddleName { get ; init; } public string LastName { get ; init; } public string FullName() { return FirstName + " " + MiddleName + " " +LastName; } } |
The code that is generated is
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER #nullable enable #endif #pragma warning disable CS8625 namespace Builder { using System; using System.Collections.Generic; using System.Linq; using Fluentify.Internal; public static partial class PersonExtensions { public static global::Builder.Person WithFirstName( this global::Builder.Person subject, string value) { subject.ThrowIfNull( "subject" ); return new global::Builder.Person { FirstName = value, MiddleName = subject.MiddleName, LastName = subject.LastName, }; } } } #pragma warning restore CS8625 #if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER #nullable restore #endif |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER #nullable enable #endif #pragma warning disable CS8625 namespace Builder { using System; using System.Collections.Generic; using System.Linq; using Fluentify.Internal; public static partial class PersonExtensions { public static global::Builder.Person WithLastName( this global::Builder.Person subject, string value) { subject.ThrowIfNull( "subject" ); return new global::Builder.Person { FirstName = subject.FirstName, MiddleName = subject.MiddleName, LastName = value, }; } } } #pragma warning restore CS8625 #if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER #nullable restore #endif |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER #nullable enable #endif #pragma warning disable CS8625 namespace Builder { using System; using System.Collections.Generic; using System.Linq; using Fluentify.Internal; public static partial class PersonExtensions { public static global::Builder.Person WithMiddleName( this global::Builder.Person subject, string ? value) { subject.ThrowIfNull( "subject" ); return new global::Builder.Person { FirstName = subject.FirstName, MiddleName = value, LastName = subject.LastName, }; } } } #pragma warning restore CS8625 #if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER #nullable restore #endif |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 | namespace Fluentify { using System; using System.Diagnostics.CodeAnalysis; [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false , AllowMultiple = false )] internal sealed class DescriptorAttribute : Attribute { public DescriptorAttribute( string value) { Value = value; } public string Value { get ; } } } |
01 02 03 04 05 06 07 08 09 10 | namespace Fluentify { using System; [AttributeUsage(AttributeTargets.Class, Inherited = false , AllowMultiple = false )] internal sealed class FluentifyAttribute : Attribute { } } |
01 02 03 04 05 06 07 08 09 10 | namespace Fluentify { using System; [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false , AllowMultiple = false )] internal sealed class IgnoreAttribute : Attribute { } } |
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 | namespace Fluentify.Internal { using System; internal static class Extensions { public static void ThrowIfNull( this object subject, string paramName) { if (subject == null ) { throw new ArgumentNullException(paramName); } } } } |
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Fluentify
Leave a Reply