{"id":13629250,"url":"https://github.com/FaustVX/PrimaryParameter","last_synced_at":"2025-04-17T04:33:25.866Z","repository":{"id":153749918,"uuid":"630129614","full_name":"FaustVX/PrimaryParameter","owner":"FaustVX","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.","archived":false,"fork":false,"pushed_at":"2024-11-23T14:58:12.000Z","size":307,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-23T15:32:43.958Z","etag":null,"topics":["csharp","csharp-library","dotnet","error","primary-constructor","source-generator"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/FaustVX.PrimaryParameter.SG","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FaustVX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-19T18:21:39.000Z","updated_at":"2024-11-23T14:58:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"97fdf6b1-0cdd-4d71-b31c-2a6f543339f3","html_url":"https://github.com/FaustVX/PrimaryParameter","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaustVX%2FPrimaryParameter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaustVX%2FPrimaryParameter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaustVX%2FPrimaryParameter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FaustVX%2FPrimaryParameter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FaustVX","download_url":"https://codeload.github.com/FaustVX/PrimaryParameter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249316074,"owners_count":21249889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-library","dotnet","error","primary-constructor","source-generator"],"created_at":"2024-08-01T22:01:05.732Z","updated_at":"2025-04-17T04:33:25.851Z","avatar_url":"https://github.com/FaustVX.png","language":"C#","funding_links":[],"categories":["Content"],"sub_categories":["83. [PrimaryParameter](https://ignatandrei.github.io/RSCG_Examples/v2/docs/PrimaryParameter) , in the [Constructor](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#constructor) category"],"readme":"# Primary Parameter\n[![NuGet version (FaustVX.PrimaryParameter.SG)](https://img.shields.io/nuget/v/FaustVX.PrimaryParameter.SG.svg)](https://www.nuget.org/packages/FaustVX.PrimaryParameter.SG/)\n[![Update NuGet](https://github.com/FaustVX/PrimaryParameter/actions/workflows/pushToNuget.yaml/badge.svg)](https://github.com/FaustVX/PrimaryParameter/actions/workflows/pushToNuget.yaml)\n\n## Description\nUsing a `Field`, `RefField`, `Property` or `DoNotUse` attribute on parameters.\n\nAutomatically generate `private readonly` fields or `private readonly ref readonly` fields or `public` properties.\n\nForbid the use of primary constructor's parameters.\n\n## Usage\n\n```cs\npartial class C([Field(Name = \"_a\", AssignFormat = \"{0}.ToString()\", Type = typeof(string)), Field(Name = nameof(C._b)), Field, Property(Setter = \"init\", Summary = \"Documentation\")]int i) // type must be partial, but can be class / struct\n{\n# region Generated members\n    // private readonly string _a = i.ToString();   // generated field (with type and formated assignment)\n    // private readonly int _b = i;                 // generated field (with computed name)\n    // private readonly int _i = i;                 // generated field\n    /// \u003csummary\u003e\n    /// Documentation\n    /// \u003c/summary\u003e\n    // private int I { get; init; } = i;            // generated Property\n# endregion\n\n    public void M0()\n    {\n        i++;                    // error on usage of i\n        Console.WriteLine(i);   // error on usage of i\n    }\n\n    public void M1()\n    {\n        var i = 0;\n        i++;                    // don't error on usage of locals\n        Console.WriteLine(_i);  // automaticaly created readonly field\n        Console.WriteLine(_a);  // automaticaly created readonly field based on Name property\n        Console.WriteLine(I);   // automaticaly created readonly property\n    }\n}\n\nref partial struct Ref([RefField(IsReadonlyRef = false, IsRefReadonly = false), RefField(Name = nameof(Ref.I), Scope = \"public\")]int i)\n{\n# region Generated members\n    private ref int _i = ref i;\n    public readonly ref readonly int I = ref i;\n# endregion\n}\n```\n\nTo enable the feature, type `[Field]`, `[RefField]`, `[Property]`, or `[DoNotUse]` before the primary parameter you want.\n\nYou can type as many attributes as you want on a single parameter (Except for `DoNotUse`).\n\n## Attribute Properties\n|Attribute|Property|Comments|Default value|\n|---------|--------|--------|-------------|\n|`Field`|`Name`|Property to modify the generated field name|`_i` (for a parameter named `i`)|\n||`IsReadnoly`|To generate the `readonly` modifier|`true`|\n||`Scope`|To change the scope of the generated property|`private`|\n||`AssignFormat`|To change the assignment for that field|`{0}`|\n||`Type`|To change the type for that field|same type as parameter|\n||`Summary`|The `\u003csummary\u003e` documentation tag|`null`|\n|`RefField`|`Name`|Property to modify the generated field name|`_i` (for a parameter named `i`)|\n||`IsReadnolyRef`|To generate the `readonly ref` modifier|`true`|\n||`IsRefReadnoly`|To generate the `ref readonly` modifier|`true`|\n||`Scope`|To change the scope of the generated property|`private`|\n||`Summary`|The `\u003csummary\u003e` documentation tag|`null`|\n|`Property`|`Name`|Property to modify the generated field name|`I` (for a parameter named `i`)|\n||`Setter`|To generate the `set`, `init` or neither accessor along the `get`|`init`|\n||`Scope`|To change the scope of the generated property|`public`|\n||`AssignFormat`|To change the assignment for that property|`{0}`|\n||`Type`|To change the type for that property|same type as parameter|\n||`Summary`|The `\u003csummary\u003e` documentation tag|`null`|\n||`WithoutBackingStorage`|Generate the body of the accessors, without a backing storage|`false`|\n|`DoNotUse`|`AllowInMemberInit`|Change to allow the use of parameter in member initializer|`true`|\n\n## Reported Diagnostics\n|Code|Title|Message|Severity|\n|----|-----|-------|--------|\n|`PC01`|Accessing a Primary Parameter|Can't access a primary parameter ('{0}') with a [Field], [RefField], [Property] or [DoNotUse] attribute, use {1}|`Error`|\n|`PC02`|Attribute generate nothing|Use this attribute only on primary parameter|`Warning`|\n|`PC03`|Attribute generate nothing|This member's name ('{0}') is already used|`Warning`\u003cbr/\u003e`Error` when a member's name is already used in the type|\n|`PC04`|RefField in non ref struct|Can't apply [RefField] in non ref struct '{0}'|`Error`|\n|`PC05`|RefField on non ref parameter|Can't apply [RefField] on non ref parameter '{0}'|`Error`|\n\n## `.csproj` properties\n|Property|Description|Default value|\n|--------|-----------|-------------|\n|Fields|||\n|`PrimaryParameter_Field_DefaultScope`|The default scope for fields generation|`private`|\n|`PrimaryParameter_Field_DefaultReadonly`|Should fields generates with `readonly` modifier|`true`|\n|Ref Fields|||\n|`PrimaryParameter_RefField_DefaultScope`|The default scope for `ref` field generation|`private`|\n|`PrimaryParameter_RefField_DefaultReadonlyRef`|Should `ref` fields generates with `readonly ref` modifier|`true`|\n|`PrimaryParameter_RefField_DefaultRefReadonly`|Should `ref` fields generates with `ref readonly` modifier|`true`|\n|Properties|||\n|`PrimaryParameter_Property_DefaultScope`|The default scope for properties generation|`public`|\n|`PrimaryParameter_Property_DefaultSetter`|Should properties generates with `set`, `init` or neither accessor|`init`|\n\n## Versions\n|Version|Date|Comments|\n|-------|----|--------|\n|v1.9.1|23/11/2024|Fixed bug (emitting the non fully-qualified type name)|\n|v1.9.0|23/11/2024|Fixed bug when the `Type` property was not specified with Arrays|\n|v1.8.1|17/11/2024|Automatically detect `partial` properties|\n|v1.8.0|15/11/2024|Added `IsPartial` for `Property`|\n|v1.7.0|23/06/2024|Added `WithoutBackingStorage` for `Property`|\n|v1.6.0|22/06/2024|Fix a bug: accept arrays|\n|v1.5.1|19/05/2024|Modified some errors message|\n|v1.5.0|18/05/2024|Don't generate `PC01` on a primary contructor base call|\n|v1.4.0|18/05/2024|Added `Conditional` on generated attributes|\n|v1.3.4|18/05/2024|Added `\u003csummary\u003e` generation|\n|v1.3.3|01/12/2023|Renamed `DontUse` to `DoNotUse`|\n|v1.3.2|19/11/2023|Don't generate the partial generated type if not needed|\n|v1.3.1|19/11/2023|Fix a bug with member initialization|\n|v1.3.0|19/11/2023|Added `DontUseAttribute`\u003cbr/\u003eAdd a code-fix for `CS0282`\u003cbr/\u003eChanged `PropertyAttribute.WithInit` to `PropertyAttribute.Setter`|\n|v1.2.0|25/08/2023|Support for default values customization|\n|v1.1.0|15/08/2023|[dotnet/roslyn#67371](https://github.com/dotnet/roslyn/issues/67371) fixed\u003cbr/\u003e(related to `v0.4.6`)|\n|v1.0.0|01/08/2023|Added code-fixes|\n|v0.4.7|16/07/2023|Don't error on `nameof` access or inside the same argument list usage|\n|v0.4.6.1|16/07/2023|Fix typos in Readme.md|\n|v0.4.6|16/07/2023|Added `RefField` attribute\u003cbr/\u003eCurrently uses `Unsafe.AsRef()` due to a compiler bug [dotnet/roslyn#67371](https://github.com/dotnet/roslyn/issues/67371)|\n|v0.4.5|18/05/2023|Added `Scope` and `IsReadonly` properties on `Field`\u003cbr/\u003e`Scope` property on `Property` defaulted to `public`|\n|v0.4.4|28/04/2023|Added `AssignFormat` and `Type` properties|\n|v0.4.3|27/04/2023|`Field` and `Property` now have `using global::System`|\n|v0.4.2|26/04/2023|Bug-fix with previous update|\n|v0.4.1|25/04/2023|More precise warnings/errors location|\n|v0.4.0|22/04/2023|Added `PC02` and `PC03` warnings/errors|\n|v0.3.1|21/04/2023|Added `Scope` property on `Property` attribute\u003cbr/\u003eAttributes are `internal`|\n|v0.3.0|20/04/2023|Added `Property` attribute|\n|v0.2.0|20/04/2023|Support for `Name` fields and multiple `Field`|\n|v0.1.0|19/04/2023|Initial release|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFaustVX%2FPrimaryParameter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFaustVX%2FPrimaryParameter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFaustVX%2FPrimaryParameter/lists"}