Skip to content

Add analyzer for RazorComponentResult parameter validation#67617

Open
dkamburov wants to merge 8 commits into
dotnet:mainfrom
dkamburov:type-safety-razor-component-result
Open

Add analyzer for RazorComponentResult parameter validation#67617
dkamburov wants to merge 8 commits into
dotnet:mainfrom
dkamburov:type-safety-razor-component-result

Conversation

@dkamburov

@dkamburov dkamburov commented Jul 6, 2026

Copy link
Copy Markdown

Add analyzer for RazorComponentResult parameter validation

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Adds a new Roslyn analyzer (BL0015) — RazorComponentResultParameterAnalyzer — that validates parameter names passed via anonymous objects to RazorComponentResult at compile time.

Description

Introduced RazorComponentResultParameterAnalyzer to warn (BL0015) when anonymous object parameters do not match component [Parameter] or [CascadingParameter] properties, unless unmatched values are captured. Registered the diagnostic, updated ComponentsApi, and added thorough unit tests covering various scenarios. Resource strings for the diagnostic were also added.

Fixes #51923

@dkamburov dkamburov requested a review from a team as a code owner July 6, 2026 11:29
Copilot AI review requested due to automatic review settings July 6, 2026 11:29
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 6, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @dkamburov. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dkamburov

Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="Infragistics, Inc"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new Components Roslyn analyzer (BL0015) to validate anonymous-object parameter names passed to RazorComponentResult<TComponent> at compile time, aiming to catch misspelled/invalid component parameter names before they produce runtime InvalidOperationExceptions.

Changes:

  • Added RazorComponentResultParameterAnalyzer (BL0015) to validate anonymous-object member names against component parameters.
  • Registered the diagnostic descriptor and added localized resource strings for title/description/message format.
  • Added unit tests covering common scenarios (unknown names, inherited parameters, CaptureUnmatchedValues, dictionary overload, unrelated types).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Components/Analyzers/src/RazorComponentResultParameterAnalyzer.cs Implements the BL0015 analyzer for RazorComponentResult<TComponent>(object parameters) anonymous-object validation.
src/Components/Analyzers/src/DiagnosticDescriptors.cs Registers BL0015 descriptor metadata.
src/Components/Analyzers/src/ComponentsApi.cs Adds RazorComponentResult<TComponent> metadata name constant for symbol lookup.
src/Components/Analyzers/src/Resources.resx Adds BL0015 resource strings (title/description/format).
src/Components/Analyzers/test/RazorComponentResultParameterAnalyzerTest.cs Adds unit tests for the analyzer behavior across key scenarios.

Comment thread src/Components/Analyzers/src/RazorComponentResultParameterAnalyzer.cs Outdated
Comment thread src/Components/Analyzers/test/RazorComponentResultParameterAnalyzerTest.cs Outdated
Comment thread src/Components/Analyzers/src/Resources.resx
dkamburov and others added 3 commits July 6, 2026 14:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

dkamburov and others added 3 commits July 8, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improving type-safety of RazorComponentResult<T>

2 participants