Skip to content

Clarify targets for primary constructor#54629

Merged
BillWagner merged 4 commits into
dotnet:mainfrom
BillWagner:attributes-primary-constructor
Jul 2, 2026
Merged

Clarify targets for primary constructor#54629
BillWagner merged 4 commits into
dotnet:mainfrom
BillWagner:attributes-primary-constructor

Conversation

@BillWagner

@BillWagner BillWagner commented Jul 2, 2026

Copy link
Copy Markdown
Member

Fixes #53684

Clarify that AttributeTargets elment on an attribute must use Constructor for the target on a constructor. Note that the article on instance constructors already had that information.


Internal previews

📄 File 🔗 Preview link
docs/csharp/advanced-topics/reflection-and-attributes/index.md Attributes
docs/csharp/language-reference/attributes/general.md Miscellaneous attributes interpreted by the C# compiler

Clarify that `AttributeTargets` elment on an attribute must use `Constructor` for the target on a constructor. Note that the article on [instance constructors](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors#primary-constructors) already had that information.
Copilot AI review requested due to automatic review settings July 2, 2026 19:42
@BillWagner BillWagner requested a review from a team as a code owner July 2, 2026 19:42
@dotnetrepoman dotnetrepoman Bot added this to the July 2026 milestone Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates C# attribute documentation to clarify how constructor-related attributes are declared and targeted, including scenarios involving primary constructors.

Changes:

  • Adds Constructor to the list of program elements that attributes can target via AttributeUsage.
  • Updates the method attribute target specifier description to include constructors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
docs/csharp/language-reference/attributes/general.md Adds constructor to the AttributeUsage target list and (recommended) should explicitly call out AttributeTargets.Constructor to match the PR intent.
docs/csharp/advanced-topics/reflection-and-attributes/index.md Clarifies that the method target specifier applies to constructors; needs a small wording tweak (Oxford comma, and optionally call out primary constructors explicitly).

Comment thread docs/csharp/advanced-topics/reflection-and-attributes/index.md Outdated
Comment thread docs/csharp/language-reference/attributes/general.md
BillWagner and others added 2 commits July 2, 2026 15:55
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@BillWagner BillWagner enabled auto-merge (squash) July 2, 2026 20:15
Comment thread docs/csharp/advanced-topics/reflection-and-attributes/index.md Outdated
Comment thread docs/csharp/language-reference/attributes/general.md Outdated
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
@BillWagner BillWagner merged commit bec00d9 into dotnet:main Jul 2, 2026
9 checks passed
@BillWagner BillWagner deleted the attributes-primary-constructor branch July 6, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Primary Constructor as an attribute target

4 participants