Refactor Circles component to use reflection-based attribute extraction with caching #7529
+249
−65
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 By Copilot
Replaced manual AttributeItem array maintenance with reflection-based automatic extraction from Circle component parameters. Implemented global static cache for performance.
Changes
AttributeItem class (
src/BootstrapBlazor.Server/Data/AttributeItem.cs)Versionproperty for XML documentation version tagsComponentAttributeCacheService (
src/BootstrapBlazor.Server/Services/ComponentAttributeCacheService.cs)ConcurrentDictionarycache for component attribute metadata[Parameter]attributes<para><version>), default valuesXmlReaderSettings, assembly location validation, specific exception handlingCircles.razor.cs (
src/BootstrapBlazor.Server/Components/Samples/Circles.razor.cs)BootstrapBlazor.csproj (
src/BootstrapBlazor/BootstrapBlazor.csproj)GenerateDocumentationFilefor XML commentsScreenshot
Attributes table correctly displays all Circle component parameters via reflection: Value, Width, StrokeWidth, Color (with enum values), ShowProgress, ChildContent, Id, AdditionalAttributes.
Regression?
Risk
Isolated change to demo component attribute display. No API changes, backward compatible. Cache invalidation available via
ClearCache().Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Original prompt
目标
重构 Circles 示例组件,从手动维护 AttributeItem 列表改为使用反射自动获取 Circle 组件的参数信息,并通过全局静态字典缓存提升性能。
需要实现的功能
1. 扩展 AttributeItem 类添加 Version 属性
文件:
src/BootstrapBlazor.Server/Data/AttributeItem.cs在 AttributeItem 类中添加一个新的 Version 属性:
2. 创建全局静态缓存服务
创建新文件:
src/BootstrapBlazor.Server/Services/ComponentAttributeCacheService.cs实现一个全局静态字典缓存服务,用于缓存组件的 AttributeItem 列表: