Instruction file imported from alxayo/vb-migration-harness (
.github/instructions/webforms-vb.instructions.md). Copyright stays with the author.
VB WebForms Code-Behind: Extraction Rules
Reading & Understanding First
- Treat each
Page_Load,Button_Click,GridView_RowCommandetc. as an entry point. - For each entry point, identify:
- Inputs: form fields,
Request.QueryString,ViewState,Sessionvariables - Outputs: UI bindings,
Response.Redirect,Label.Text, GridView data sources - Side effects: DB writes, SOAP calls, file I/O
- Hidden invariants: conditional branches, null checks, default values applied silently
- Inputs: form fields,
- Do not assume two event handlers that look similar DO the same thing — verify each one.
- The custom expression evaluator / transformation module is a critical black box: do not modify it without golden-master tests in place.
Before Any Edit
- Confirm a characterization test exists that covers the event handler's workflow.
- If no test exists, stop and create one first.
- Use
#codebaseand#usagesto find all callers of any method you intend to move.
Extraction Pattern (for each event handler)
- Enumerate the handler's inputs, outputs, and side-effects.
- Extract pure logic (validation, calculation, transformation) into C# in
/src/Domain/. - Extract use-case orchestration (call domain + call infra) into C# in
/src/App/. - Leave the VB code-behind as a thin adapter:
' After extraction — VB event handler should look like this: Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Dim request = New MyRequest(txtField.Text, ddlOption.SelectedValue) Dim result = _myService.Execute(request) ' C# service via COM-interop or side-by-side lblResult.Text = result.Message End Sub - Verify tests still pass; fix regressions before proceeding.
Do NOT Do
- Do not refactor VB to be "cleaner" unless it helps extraction.
- Do not move logic in the same file without a test oracle in place.
- Do not silently drop ViewState or Session usage — catalog it; some hold genuine state.
- Do not convert DataSet/DataTable to something else in the VB layer; leave that for the
C#
Data Modernizerstep.
AjaxControlToolkit
- Document every control used and what user action it enables.
- Do not attempt in-place replacement; note it in the workflow inventory for Phase 6 (UI Rebuild).
- During extraction, treat AJAX behaviors as UI concerns only — they don't affect the business rules being extracted.