Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Summary By Copilot

Replaced manual AttributeTable Items="@GetAttributes()" with Name="ComponentName" across 130+ sample files, leveraging Source Generator for automatic attribute extraction. Eliminates ~9,000 lines of hand-maintained attribute definitions.

Changes

  • Razor files: Updated AttributeTable declarations from Items="@GetAttributes()" to Name="ComponentName"
  • Code-behind files: Removed 124 GetAttributes() methods now obsolete with Source Generator
  • Multi-table cases: Preserved secondary AttributeTables (e.g., ConsoleMessageItem, TimelineItem) that use Items for non-component types
  • XML comments: Cleaned orphaned documentation from removed methods

Examples

Before:

<AttributeTable Items="@GetAttributes()" />
private AttributeItem[] GetAttributes() =>
[
    new() { Name = "Target", Description = Localizer["Desc1"], Type = "string", ... }
];

After:

<AttributeTable Name="GoTop" />
// Method removed - attributes auto-generated from component source

Multi-table preservation:

<AttributeTable Name="Console" />
<AttributeTable Items="@GetItemAttributes()" Title="@Localizer["ConsoleMessageItem"]" />

Component naming

Applied plural-to-singular convention with special cases:

  • Buttons.razorButton
  • GoTops.razorGoTop
  • UploadInputs.razorInputUpload
  • IntersectionObservers.razorIntersectionObserver

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Mechanical refactor using Source Generator already implemented. Attribute data source changes from manual to generated; display logic unchanged.

Verification

  • Manual (required)
  • Automated

Server project builds with 0 errors/warnings. All 130+ components verified with correct Name mappings.

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch
Original prompt

需求描述

现在 Source Generator 已经实现,AttributeTable 组件支持通过 Name 参数自动加载组件属性。需要将 Samples 目录下所有使用 <AttributeTable Items="@GetAttributes()" /> 的文件替换为 <AttributeTable Name="ComponentName" />

需要更新的文件列表

根据搜索结果,以下文件需要更新(可能不完整,需要全面扫描):

  1. src/BootstrapBlazor.Server/Components/Samples/GoTops.razor
  2. src/BootstrapBlazor.Server/Components/Samples/Transitions.razor
  3. src/BootstrapBlazor.Server/Components/Samples/UploadInputs.razor
  4. src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
  5. src/BootstrapBlazor.Server/Components/Samples/Speeches/SpeechWaves.razor
  6. src/BootstrapBlazor.Server/Components/Samples/Topologies.razor
  7. src/BootstrapBlazor.Server/Components/Samples/IntersectionObservers.razor
  8. src/BootstrapBlazor.Server/Components/Samples/Carousels.razor
  9. src/BootstrapBlazor.Server/Components/Samples/Consoles.razor
  10. src/BootstrapBlazor.Server/Components/Samples/Timelines.razor
  11. src/BootstrapBlazor.Server/Components/Samples/Repeaters.razor
  12. src/BootstrapBlazor.Server/Components/Samples/Scrolls.razor
  13. src/BootstrapBlazor.Server/Components/Samples/ListGroups.razor
  14. src/BootstrapBlazor.Server/Components/Samples/Splits.razor
  15. src/BootstrapBlazor.Server/Components/Samples/Drawers.razor
  16. src/BootstrapBlazor.Server/Components/Samples/ImageViewers.razor
  17. src/BootstrapBlazor.Server/Components/Samples/SelectTables.razor
  18. src/BootstrapBlazor.Server/Components/Samples/ListViews.razor

以及其他所有 Samples 目录下包含 <AttributeTable Items="@GetAttributes()" /> 的文件。

替换规则

对于标准情况

原代码:

<AttributeTable Items="@GetAttributes()" />

替换为:

<AttributeTable Name="ComponentName" />

其中 ComponentName 是组件的实际名称,需要根据文件路径推断:

  • GoTops.razor<AttributeTable Name="GoTop" />
  • Transitions.razor<AttributeTable Name="Transition" />
  • UploadInputs.razor<AttributeTable Name="InputUpload" />
  • Carousels.razor<AttributeTable Name="Carousel" />
  • Consoles.razor<AttributeTable Name="Console" />
  • Timelines.razor<AttributeTable Name="Timeline" />
  • Repeaters.razor<AttributeTable Name="Repeater" />
  • Scrolls.razor<AttributeTable Name="Scroll" />
  • ListGroups.razor<AttributeTable Name="ListGroup" />
  • Splits.razor<AttributeTable Name="Split" />
  • Drawers.razor<AttributeTable Name="Drawer" />
  • ImageViewers.razor<AttributeTable Name="ImageViewer" />
  • SelectTables.razor<AttributeTable Name="SelectTable" />
  • ListViews.razor<AttributeTable Name="ListView" />
  • Topologies.razor<AttributeTable Name="Topology" />
  • IntersectionObservers.razor<AttributeTable Name="IntersectionObserver" />
  • SpeechWaves.razor<AttributeTable Name="SpeechWave" />

对于带有 Title 参数的情况

原代码:

<AttributeTable Items="@GetAttributes()" Title="@Localizer["AttTitle"]" />

替换为:

<AttributeTable Name="ComponentName" Title="@Localizer["AttTitle"]" />

对于多个 AttributeTable 的情况

有些示例文件包含多个 AttributeTable,例如:

Consoles.razor:

<AttributeTable Items="@GetAttributes()" />
<AttributeTable Items="@GetItemAttributes()" Title="@Localizer["ConsoleMessageItem"]" />

第一个 AttributeTable 是主组件的属性表,应该替换为:

<AttributeTable Name="Console" />
<AttributeTable Items="@GetItemAttributes()" Title="@Localizer["ConsoleMessageItem"]" />

第二个 AttributeTable 是子项的属性表(ConsoleMessageItem),由于不是标准组件,保持使用 Items 参数。

Timelines.razor:

<AttributeTable Items="GetAttributes()" />
<AttributeTable Items="GetTimelineItemAttributes()" Title="@Localizer["TimelinesAttributeTitle"]" />

第一个替换为:

<AttributeTable Name="Timeline" />
<AttributeTable Items="GetTimelineItemAttributes()" Title="@Localizer["TimelinesAttributeTitle"]" />

组件名称推断规则

  1. 通常文件名的复数形式对应单数组件名(如 Tabs.razorTab

  2. 某些组件的命名需要特别注意:

    • Circles.razorCircle
    • Buttons.razorButton
    • Alerts.razorAlert
  3. 如果不确定组件名称,可以查看 .razor 文件中使用的组件标签名

同时需要删除的代码

在对应的 .razor.cs 文件中,删除 GetAttributes() 方法(如果该方法只是返回组件参数列表)。

例如,在 GoTops.razor.cs 中删除:

private AttributeItem[] GetAttributes() => 
[
    // ... 属性列表
];

保留的情况:

  • 如果 GetAttributes() 方法用于多个 AttributeTable(如 GetItemAttributes(), GetTimelineItemAttributes()
  • 如果是自定义的属性项(非标准组件参数)

验证标准

  1. 所有示例页面的属性表格应正常显示
  2. 属性信息应该与原有手动维护的版本一致
  3. 编译无错误和警告
  4. 删除的 GetAttributes() 方法不应被其他地方引用

注意事项

  1. 全面扫描 Samples 目录,不要遗漏任何文件
  2. 仔细推断正确的组件名称
  3. 对于有多个 AttributeTable 的情况,只替换主组件的那个
  4. 保持代码格式一致性
  5. 确保所有改动后的示例页面都能正常运行

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bb-auto
Copy link

bb-auto bot commented Jan 16, 2026

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

Copilot AI changed the title [WIP] Update samples to use AttributeTable with Name parameter Migrate AttributeTable from manual Items to Source Generator Name parameter Jan 16, 2026
Copilot AI requested a review from ArgoZhang January 16, 2026 03:50
@ArgoZhang ArgoZhang closed this Jan 16, 2026
@ArgoZhang ArgoZhang deleted the copilot/update-attribute-table-samples branch January 16, 2026 08:23
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.

2 participants