-
Notifications
You must be signed in to change notification settings - Fork 71
Add custom control adapter layer with Roslyn analyzer for Web Forms migration #329
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
Conversation
…CompositeControl Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
…and clarify documentation Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
|
@copilot For those Required changes, can we create a Roslyn Analyzer with a fixer to help implement those items? |
Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
Created a Roslyn analyzer package ( BWFC001: Detects public properties in WebControl/CompositeControl classes missing BWFC002: Detects Both analyzers work in Visual Studio, VS Code, and other Roslyn-powered IDEs with quick-fix support (Ctrl+.). See commit 7f1344d and the analyzer README for details. |
…tainsKey Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
… can be combined Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
@copilot Let's not call these classes "shims" but rather "adapters" |
Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
Updated terminology from "shim" to "adapter" throughout the documentation in commit 63f7f3c. Changed references in:
Note: The branch name |
| /// <param name="writer">The HtmlTextWriter to write output to.</param> | ||
| internal void RenderControl(HtmlTextWriter writer) | ||
| { | ||
| Render(writer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Instead of forcing every implementation to call AddBaseAttributes(writer) - why not call that method here and eliminate the requirement? We can then make AddBaseAttributes private and eliminate the need for that analyzer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented in commit 981fa77. Base attributes (ID, CssClass, Style) are now automatically added in BuildRenderTree before calling the user's Render method. This eliminates the need for:
- Manual
AddBaseAttributes(writer)calls in every implementation - The BWFC002 analyzer and its code fix provider
The AddBaseAttributes method is now private. All test components updated and 518 tests passing. Documentation updated to reflect automatic attribute application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unnecessary analyzer and fixer for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Remove the unnecessary analyzer and fixer for the AddBaseAttributes method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already completed in commit 981fa77. The BWFC002 analyzer and code fix provider have been removed. Only BWFC001 (Parameter attribute detector) remains in the analyzer package.
… AddBaseAttributes() calls and BWFC002 analyzer Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
Web Forms applications often contain custom controls inheriting from
WebControlorCompositeControlthat useHtmlTextWriterfor rendering. This adds a compatibility adapter layer enabling migration with minimal code changes.Implementation
Core Adapter Classes
HtmlTextWriter- Buffers HTML output with Web Forms-compatible API (RenderBeginTag,AddAttribute,AddStyleAttribute)WebControl- Base class adapter for simple custom controls; extendsBaseStyledComponentCompositeControl- Base class adapter for controls with child components; manages child lifecycle and renderingRoslyn Analyzer
BlazorWebFormsComponents.Analyzers- NuGet package providing automated migration assistance[Parameter]attributes with automatic code fixKey Behaviors
Migration Example
Web Forms:
Blazor (minimal changes with analyzer assistance):
Required changes: Add
[Parameter]to properties (auto-fixed by BWFC001 analyzer). Base attributes are automatically applied.Testing
23 tests covering rendering, attribute handling, style concatenation, child control management, and encoding. Analyzer builds successfully and integrates with the solution.
Documentation
docs/Migration/Custom-Controls.mdwith side-by-side examples, best practices, and common pitfallssrc/BlazorWebFormsComponents.Analyzers/README.mdwith usage instructions and examplesOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.