Workflows

Refactor a C# solution with Gravity, step by step

How to hand a multi-file refactor to Gravity: describe the outcome, review the plan, approve the diffs and let it run the build and the tests.

Refactors are where an AI assistant that only suggests code loses most of its value. You still have to find every usage, edit every file and run the build yourself. Gravity is built to carry the whole task: it plans the steps, edits the files, runs the build and the tests, and replans when a step fails.

This walkthrough uses a common job in C# solutions: replacing an old client class with a new one across the codebase.

Set it up safely

Commit your work first, so the diff of the refactor is the only thing that changes. Then set the development mode to Review in Settings. In Review mode, read-only operations such as reading, searching and listing still run automatically, but file writes, deletions and shell commands show an approval card with a preview first.

Describe the outcome, not the steps

Write the request the way you would explain it to a colleague. Be specific about what must not change.

Replace every use of LegacyClient with ApiClient across the solution.
Keep the public method signatures. Then run dotnet build and dotnet test
and fix anything that breaks.

Read the plan

Gravity turns the request into an explicit plan before it touches anything. A plan for this task usually looks like this: search the solution for usages, edit the files that came back, run the tests, and verify the result. Every step can use the output of the steps before it, which is why the edit step works on the files the search step found and not on a guess.

step1  search   find usages of LegacyClient
step2  file     edit $step1.files
step3  shell    dotnet test
step4  verify   $step3 passed

Use the code analysis to see the blast radius

Gravity includes Roslyn-based analysis. It loads your solution through MSBuild, can find every reference to a symbol grouped by file, and separates test code from production code. That impact report, the blast radius of a symbol, is what lets an agent know how many files a rename or replacement will touch before it edits anything.

Approve the diffs

As the edit step runs, each write shows a diff. Read it, approve it, or reject it and give guidance so the agent retries. Nothing changes without your answer, and a rejected edit does not stop the task.

Let it verify

After the edits, Gravity runs dotnet build and dotnet test. If a step fails, it reads the error, retries and replans instead of stopping. When it cannot reach a passing result, it tells you why, so you know what to look at yourself.

Review the result in your usual tools

Finish like you would with any change: look at the diff in your Git client, run the full test suite once more and commit. If something is wrong, the commit you made at the start makes it a one-line rollback.

Gravity is free to download with an account, so you can run this exact workflow on a branch of your own project today.

Download Gravity free