Skip to content

Use pattern matching to avoid as followed by a null check#9569

Merged
glen-84 merged 1 commit intomainfrom
gai/use-pattern-matching
Apr 17, 2026
Merged

Use pattern matching to avoid as followed by a null check#9569
glen-84 merged 1 commit intomainfrom
gai/use-pattern-matching

Conversation

@glen-84
Copy link
Copy Markdown
Member

@glen-84 glen-84 commented Apr 17, 2026

Summary of the changes (Less than 80 chars)

  • Use pattern matching to avoid as followed by a null check.

Copilot AI review requested due to automatic review settings April 17, 2026 09:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + null check patterns to is not <Type> <name> in core type initialization logic.
  • Apply the same refactor in analyzer and code-fix provider implementations.
  • Update .editorconfig to enable IDE0019 and disable overlapping Roslynator rule RCS1221.

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.

Comment thread .editorconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants