Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Primary Constructor Parameter Member Generation Coverage #780

Open
MarkMichaelis opened this issue May 16, 2024 · 0 comments
Open
Labels
manuscript Something that needs the manuscript to be updated for

Comments

@MarkMichaelis
Copy link
Member

  • When a primary constructor parameter is used, the compiler captures the constructor parameter in a private field with a compiler-generated name.
    If a primary constructor parameter isn't used in the body of the type, no private field is captured. (That rule prevents accidentally allocating two copies of a primary constructor parameter that's passed to a base constructor.)
  • If the type includes the record modifier, the compiler instead synthesizes a public property with the same name as the primary constructor parameter.
  • For record class types, if a primary constructor parameter uses the same name as a base primary constructor, that property is a public property of the base record class type. It isn't duplicated in the derived record class type. These properties aren't generated for non-record types.
    See https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors#primary-constructors
@MarkMichaelis MarkMichaelis added the manuscript Something that needs the manuscript to be updated for label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
manuscript Something that needs the manuscript to be updated for
Projects
None yet
Development

No branches or pull requests

1 participant