Skip to content

C# 14: Support the field keyword.#21309

Draft
michaelnebel wants to merge 4 commits intogithub:mainfrom
michaelnebel:csharp14/field
Draft

C# 14: Support the field keyword.#21309
michaelnebel wants to merge 4 commits intogithub:mainfrom
michaelnebel:csharp14/field

Conversation

@michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Feb 11, 2026

In this PR we make support for the C# 14 field keyword in properties. Using the keyword field in property accessors implicitly make a synthetic backing field.
That is, you can declare

public class C
{
    public object Prop1
    {
        get { return field; }
        set { field = value; }
    }
}

Some notes on the implementation.

  • An important implementation detail is that PropertyField objects are hashed on the (field,property) pair and not only on the field itself. The symbol visitor is being applied to all backing fields, which means that Field objects are created for backing fields as well - however, the DB is not populated based on these as they are implicitly declared.
  • An auto-property has a similar backing field, which we are not extracting.
  • We only extract the property backing field, if it is referenced by the use of the field keyword. That is, we only extract the backing field, if we are encountering an expression with FieldExpression kind.

@github-actions github-actions bot added the C# label Feb 11, 2026
@michaelnebel michaelnebel changed the title C# 14: Support for field usage in properties. C# 14: Support the field keyword. Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant