Skip to content

feat: 源生成重写添加SetParametersAsync方法 #6235

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kimdiego2098
Copy link
Collaborator

@kimdiego2098 kimdiego2098 commented Jun 15, 2025

重写SetParametersAsync,原生SetParametersAsync方法使用大量缓存,属性多并且属于泛型组件的话,,WriterForType的缓存占用比较高,参考 dotnet/aspnetcore#44693

Summary by Sourcery

Introduce source-generated SetParametersAsync to optimize generic component parameter handling and reduce caching overhead

New Features:

  • Add [BlazorSetParametersAsyncGenerator.GenerateSetParametersAsync] attribute to Checkbox, Radio, and Table components to enable source-generated SetParametersAsync

Build:

  • Register the BlazorSetParametersAsyncGenerator in the project file to support source generation

Copy link

bb-auto bot commented Jun 15, 2025

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

@bb-auto bb-auto bot requested a review from ArgoZhang June 15, 2025 17:16
Copy link
Contributor

sourcery-ai bot commented Jun 15, 2025

Reviewer's Guide

Introduce a source-generator-based override for SetParametersAsync on key components to reduce reflection/caching overhead by applying the GenerateSetParametersAsync attribute and updating the project to include the generator.

Sequence Diagram: Overridden SetParametersAsync Execution Flow

sequenceDiagram
    participant BlazorRuntime as "Blazor Runtime"
    participant ComponentInstance as "Component (e.g., Checkbox)"
    participant GeneratedCode as "Source-Generated SetParametersAsync()"

    BlazorRuntime->>ComponentInstance: SetParametersAsync(parameters)
    activate ComponentInstance
    ComponentInstance->>GeneratedCode: Invokes (replaces default Blazor behavior)
    activate GeneratedCode
    GeneratedCode-->>ComponentInstance: Efficiently processes parameters
    deactivate GeneratedCode
    ComponentInstance-->>BlazorRuntime: Task completed
    deactivate ComponentInstance
Loading

Class Diagram: Component Updates for Source-Generated SetParametersAsync

classDiagram
    class Checkbox~TValue~ {
        + [BlazorSetParametersAsyncGenerator.GenerateSetParametersAsync]
        + SetParametersAsync(ParameterView parameters) Task
    }

    class Radio~TValue~ {
        + [BlazorSetParametersAsyncGenerator.GenerateSetParametersAsync]
        + SetParametersAsync(ParameterView parameters) Task
    }
    Radio --|> Checkbox~TValue~

    class Table~TItem~ {
        + [BlazorSetParametersAsyncGenerator.GenerateSetParametersAsync]
        + SetParametersAsync(ParameterView parameters) Task
    }
Loading

File-Level Changes

Change Details Files
Enable source-generated SetParametersAsync for components
  • Add [BlazorSetParametersAsyncGenerator.GenerateSetParametersAsync] to Checkbox
  • Add [BlazorSetParametersAsyncGenerator.GenerateSetParametersAsync] to Radio
  • Add [BlazorSetParametersAsyncGenerator.GenerateSetParametersAsync] to Table
src/BootstrapBlazor/Components/Checkbox/Checkbox.razor.cs
src/BootstrapBlazor/Components/Radio/Radio.razor.cs
src/BootstrapBlazor/Components/Table/Table.razor.cs
Integrate source generator into build
  • Update BootstrapBlazor.csproj to reference the BlazorSetParametersAsyncGenerator source generator
src/BootstrapBlazor/BootstrapBlazor.csproj

Possibly linked issues

  • #14371235: PR rewrites SetParametersAsync for Table component, addressing the redraw issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 15, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @kimdiego2098 - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant