Dictionary expressions public api proposal
- 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
Assessment
This issue has not been assessed yet.