dotnet / dotnet/roslyn

Dictionary expressions public api proposal

Open
#84,112 0 comments 0 reactions 1 assignee Claimed by @333fred View on GitHub
Area-Compilers Concept-API Feature - Dictionary Expressions Feature Request
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

## Background and Motivation

[Dictionary expressions](https://github.com/dotnet/roslyn/issues/81860) add a `k: v`
collection element. We need public syntax APIs to inspect and construct it, mirroring
the experimental `WithElementSyntax`. All members are gated `[RSEXPERIMENTAL006]` while
the feature is in preview. https://github.com/dotnet/roslyn/issues/84198 tracks removing the experimental flags.

## Proposed API

New node in `Syntax.xml` (the `KeyValuePairElementSyntax` type, `SyntaxFactory` methods,
and visitor/rewriter methods are all generated from this):

```diff

...


+
+
+
+
+
+
+
+

```

New `SyntaxKind`:

```diff
public enum SyntaxKind : ushort
{
+ KeyValuePairElement = 9083,
}
```

## Usage Examples

```csharp
var kvps = root.DescendantNodes().OfType();

var element = SyntaxFactory.KeyValuePairElement(
LiteralExpression(SyntaxKind.StringLiteralExpression, Literal("one")),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1)));
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.