RSCG – Lombok.NET
RSCG – Lombok.NET
name | Lombok.NET |
nuget | https://www.nuget.org/packages/Lombok.NET/ |
link | https://github.com/CollinAlpert/Lombok.NET |
author | Colin Alpert |
Generating toString from props/fields. Other demos on site
This is how you can use Lombok.NET .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net7.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <ItemGroup> <PackageReference Include="Lombok.NET" Version="2.1.2" /> </ItemGroup> <PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> </PropertyGroup> </Project>
The code that you will use is
// See https://aka.ms/new-console-template for more information using Lombok.NETDemo; Console.WriteLine("Hello, World!"); Person p = new(); p.FirstName = "Andrei"; p.LastName="Ignat"; Console.WriteLine(p.ToString());
using Lombok.NET; namespace Lombok.NETDemo; [ToString(AccessTypes=AccessTypes.Public, MemberType=MemberType.Property)] //[AllArgsConstructor(AccessTypes=AccessTypes.Public,MemberType = MemberType.Property)] public partial class Person { public Person() { } public string? FirstName{ get; set; } public string? LastName { get; set; } public string FullName { get { return FirstName + " " + LastName; } } }
The code that is generated is
// <auto-generated/> namespace Lombok.NETDemo; #nullable enable public partial class Person { public override string ToString() { return $"Person: FirstName={FirstName}; LastName={LastName}; FullName={FullName}"; } }
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Lombok.NET
Leave a Reply