New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Deconstruct method for syntax nodes #52784
Comments
Well, you can write this: RecordDeclarationSyntax { RawKind: (int)SyntaxKind.RecordStructDeclaration, ParameterList: not null } The drawback is that RawKind is typed as an int. We could have a CSharpKind property on the type that then exposes that as SyntaxKind which would make thigns nicer. It's totally unclear to me why we made Kind an extension method... |
According to 93e9eaf#r11017500 back in 2015,
|
Seems like it should have been a property. But alas here, we are. Maybe we might make it possible for pattern matching to support something like |
That's not that bad. But I'd still prefer Deconstruct cause it perfectly frame the type check part of the match. just my 2c.
I think extension props is more likely than methods in patterns though. |
I have been thinking off and on about the ergonomics of this pattern, particularly about the fact that these forms would work:
But this would not:
I don't know if this is particularly solvable or not. But it feels "weird", similar to how before we had type patterns users had to do e.g. |
I don't think that matters, we probably wouldn't want to do any of those? See some sample usages in #53553 (https://github.com/dotnet/roslyn/.../UseRecursivePatternsCodeRefactoringProvider.cs) |
It looks like this is already present in Workspaces/SharedUtilitiesAndExtensions, so this issue tracks making the API available in the compiler layer. Lines 24 to 27 in e43614f
|
This made me realize a
void Deconstruct(this SyntaxNode, out SyntaxKind)
might be actually useful. Currently matching multi-kind nodes is kind of ugly..Originally posted by @alrz in #52702 (comment)
I recall often being stymied by the inability to match the SyntaxKind when pattern matching against a syntax node. It might work nicely to introduce an internal extension which lets us deconstruct the SyntaxKind.
The text was updated successfully, but these errors were encountered: