Use pattern matching to avoid as followed by a null check#9569
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the codebase to prefer C# pattern matching over as casts followed by null checks, and adds editor configuration to enforce this style consistently.
Changes:
- Refactor
as+nullcheck patterns tois not <Type> <name>in core type initialization logic. - Apply the same refactor in analyzer and code-fix provider implementations.
- Update
.editorconfigto enableIDE0019and disable overlapping Roslynator ruleRCS1221.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/src/Types/Configuration/TypeInitializer.cs | Refactors batch resolver method discovery to use pattern matching. |
| src/HotChocolate/Core/src/Types.Analyzers/WrongAuthorizationAttributeAnalyzer.cs | Uses pattern matching when resolving containing type declarations. |
| src/HotChocolate/Core/src/Types.Analyzers/ShareableInterfaceTypeCodeFixProvider.cs | Uses pattern matching when resolving the parent attribute list. |
| src/HotChocolate/Core/src/Types.Analyzers/QueryContextProjectionCodeFixProvider.cs | Uses pattern matching when resolving the parent attribute list. |
| src/HotChocolate/Core/src/Types.Analyzers/IdAttributeOnRecordParameterCodeFixProvider.cs | Uses pattern matching with null-conditional access for attribute list discovery. |
| .editorconfig | Enables IDE0019 and disables RCS1221 to prefer pattern matching enforcement. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the changes (Less than 80 chars)
asfollowed by anullcheck.