Skip to content

[API proposal] Syntax changes for field keyword #74937

@cston

Description

@cston

Background and Motivation

Syntax API changes to support the field keyword in properties.

// Example use of the field keyword
object Property
{
    get { return field; }
    set { field = value; }
}

Proposed API

namespace Microsoft.CodeAnalysis.CSharp
{
    public enumm SyntaxKind : ushort
    {
        // ...

        FieldKeyword = 8412,

        // ...
        
+       FieldExpression = 8757,
    }
}

namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
    
+   public sealed class FieldExpressionSyntax : ExpressionSyntax
+   {        
+       /// <summary>SyntaxToken representing the field keyword.</summary>
+       public SyntaxToken Token { get; }
+
+       public FieldExpressionSyntax Update(SyntaxToken token);
+
+       public FieldExpressionSyntax WithToken(SyntaxToken token);
+   }
}

Usage Examples

// some lines of code here

Alternative Designs

Risks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.Feature Requestapi-approvedAPI was approved in API review, it can be implementeduntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions