Skip to content

Ensure Primary Constructor Parameter Member Generation Coverage #780

@MarkMichaelis

Description

@MarkMichaelis
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    manuscriptSomething that needs the manuscript to be updated for

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions