RSCG – QuickConstructor
| name | QuickConstructor |
| nuget | https://www.nuget.org/packages/QuickConstructor |
| link | https://github.com/flavien/QuickConstructor |
| author | Flavien Charlon |
Fast add constructors that are read only FIELDS
Has multiple other features
This is how you can use QuickConstructor .
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="QuickConstructor" Version="1.0.5" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
The code that you will use is
using QuickConstructorDemo; var p = new Person("Andrei","Ignat");
using QuickConstructor.Attributes;
namespace QuickConstructorDemo;
[QuickConstructor]
internal partial class Person
{
private readonly string FirstName;
private readonly string? LastName;
}
The code that is generated is
/// <auto-generated>
/// This code was generated by the QuickConstructor source generator.
/// </auto-generated>
#nullable enable
namespace QuickConstructorDemo
{
partial class Person
{
/// <summary>
/// Initializes a new instance of the <see cref="Person" /> class.
/// </summary>
public Person(string @firstName,string? @lastName)
{
if (@firstName == null)
throw new global::System.ArgumentNullException(nameof(@firstName));
this.@FirstName = @firstName;
this.@LastName = @lastName;
}
}
}
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/QuickConstructor
Leave a Reply