Clarify targets for primary constructor#54629
Merged
BillWagner merged 4 commits intoJul 2, 2026
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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
methodattribute 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). |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
gewarren
approved these changes
Jul 2, 2026
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
adegeo
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #53684
Clarify that
AttributeTargetselment on an attribute must useConstructorfor the target on a constructor. Note that the article on instance constructors already had that information.Internal previews