Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for [Id] attribute on record primary constructor parameters#9791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/add-id-annotations-support

Conversation

Copy link
Contributor

CopilotAI commentedNov 18, 2025
edited
Loading

Enables[Id] attribute to be applied directly to record primary constructor parameters, eliminating the verbose[property: Id(0)] syntax.

Changes

  • IdAttribute: AddedAttributeTargets.Parameter to supported targets
  • FieldIdAssignmentHelper: EnhancedExtractFieldIdAnnotations() to check primary constructor parameters for[Id] attributes when processing properties that match those parameters
  • Tests: Added serialization round-trip tests and code generator snapshot tests for the new syntax

Usage

// Before[GenerateSerializer]publicrecordDeposit([property:Id(0)]decimalAmount)// After[GenerateSerializer]publicrecord Deposit([Id(0)]decimalAmount)

Both syntaxes remain supported. The new syntax works for simple records and records with additional properties:

[GenerateSerializer]publicrecordEmployee([Id(0)]intId,[Id(1)]stringName){[Id(2)]publicstringDepartment{get;init;}}

Resolves#9092

Original prompt

This section details on the original issue you should resolve

<issue_title>Add support for [Id] annotations on record primary constructor parameters</issue_title>
<issue_description>Now that proper support for records (in referenced assemblies too) is implemented, it would be great to be able to annotate the ctor parameter itself, rather than the more verbose (and harder to discover) syntax for annotating the backing property generated for it. This would allow to go from this:

publicrecordDeposit([property:Id(0)]decimalAmount)

to this:

publicrecordDeposit([Id(0)]decimalAmount)

The generator could just treat an Id attribute on a same-name ctor parameter as a property of the type as if was applied to the property, simplifying its usage in this particular scenario and saving non-trivial amount of keystrokes (for even just a few parameters, having to addproperty: to every property can quickly become annoying).

Related:#9092</issue_description>

<agent_instructions>Make sure to add tests which exercise this path! Add both serialization tests and codegenerator output verification tests</agent_instructions>

Comments on the Issue (you are@copilot in this section)

@ReubenBondThis would be great, if someone can make it work. It might involve finding the primary ctor for a record and matching the attributes on the ctor params with the resulting properties.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our2 minute survey.

Microsoft Reviewers:Open in CodeFlow

…tersCo-authored-by: ReubenBond <203839+ReubenBond@users.noreply.github.com>
CopilotAI changed the title[WIP] Add support for Id annotations on record parametersAdd support for [Id] attribute on record primary constructor parametersNov 18, 2025
Copilot finished work on behalf ofReubenBondNovember 18, 2025 16:50
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ReubenBondReubenBondAwaiting requested review from ReubenBond

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add support for [Id] annotations on record primary constructor parameters Issue with generated codec for referenced project record message type

2 participants

@ReubenBond

[8]ページ先頭

©2009-2025 Movatter.jp