FaustVX.PrimaryParameter.SG 0.4.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package FaustVX.PrimaryParameter.SG --version 0.4.2                
NuGet\Install-Package FaustVX.PrimaryParameter.SG -Version 0.4.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FaustVX.PrimaryParameter.SG" Version="0.4.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FaustVX.PrimaryParameter.SG --version 0.4.2                
#r "nuget: FaustVX.PrimaryParameter.SG, 0.4.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FaustVX.PrimaryParameter.SG as a Cake Addin
#addin nuget:?package=FaustVX.PrimaryParameter.SG&version=0.4.2

// Install FaustVX.PrimaryParameter.SG as a Cake Tool
#tool nuget:?package=FaustVX.PrimaryParameter.SG&version=0.4.2                

Primary Parameter

NuGet version (FaustVX.PrimaryParameter.SG) Update NuGet

Description

Using a Field or Property attribute on parameters.

Automaticaly generate private readonly fields or private properties.

Forbid the use of primary constructor's parameters.

Usage

partial class C([Field(Name = "_a"), [Field(Name = nameof(C._b))], Field, [Property(WithInit = true)]]int i) // type must be partial, but can be class / struct
{
# region Generated members
    // private readonly int _a = i;     // generated field
    // private readonly int _b = i;     // generated field (with computed name)
    // private readonly int _i = i;     // generated field
    // private int { get; init; } = i;  // generated Property
# endregion

    public void M0()
    {
        i++;                    // error on usage of i
        Console.WriteLine(i);   // error on usage of i
    }

    public void M1()
    {
        var i = 0;
        i++;                    // don't error on usage of locals
        Console.WriteLine(_i);  // automaticaly created readonly field
        Console.WriteLine(_a);  // automaticaly created readonly field based on Name property
        Console.WriteLine(I);   // automaticaly created readonly property
    }
}

To enable the feaure, type [Field] or [Property] before the primary parameter you want.

You can type as many attributes as you want on a single parameter.

Attribute Properties

Attribute Property Comments Default value
Field Name Property to modify the generated field name _i (for a parameter named i)
Property Name Property to modify the generated field name I (for a parameter named i)
WithInit To generate the init accessor along the get false
Scope To change the scope of the generated property private

Reported Diagnostics

Code Title Message Severity
PC01 Accessing a Primary Parameter Can't access a primary parameter ('{0}') with a [Field] or [Property] attribute, use {1} Error
PC02 Attribute generate nothing Use this attributes only on primary parameter Warning
PC03 Attribute generate nothing This member's name ('{0}') is already used Warning</br>Error when a member's name is already used in the type

Versions

Version Date Comments
v0.4.2 26/04/2023 bug-fix with previous update
v0.4.1 25/04/2023 More precise warnings/errors location
v0.4.0 22/04/2023 Added PC02 and PC03 warnings/errors
v0.3.1 21/04/2023 Added Scope property on Property attribute</br>Attributes are internal
v0.3.0 20/04/2023 Added Property attribute
v0.2.0 20/04/2023 Support for Name fields and multiple Field
v0.1.0 19/04/2023 Initial release
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.8.0 37 11/15/2024
1.7.0 376 6/22/2024
1.6.0 98 6/22/2024
1.5.1 208 5/18/2024
1.5.0 97 5/18/2024
1.4.0 102 5/18/2024
1.3.4 96 5/18/2024
1.3.3 411 12/1/2023
1.3.2 199 11/19/2023
1.3.1 142 11/19/2023
1.3.0 129 11/19/2023
1.2.0 264 8/24/2023
1.1.0 256 8/15/2023
1.0.0 156 7/31/2023
0.4.7 157 7/16/2023
0.4.6.1 159 7/16/2023
0.4.6 157 7/16/2023
0.4.5 142 5/17/2023
0.4.4 180 4/27/2023
0.4.3 175 4/27/2023
0.4.2 174 4/26/2023
0.4.1 180 4/25/2023
0.4.0 191 4/22/2023
0.3.1 181 4/20/2023
0.3.0 184 4/20/2023
0.2.0 177 4/20/2023
0.1.0 190 4/19/2023