[refactoring]
Moves a type to a different file and/or namespace and updates references. An applied refactor keeps the line endings each file already has. A file that mixes LF and CRLF is written with the ending it uses most. The unified diff normalizes both sides to LF, so it shows the edit and not the endings.
C# refactors are semantic operations, not search-and-replace operations.
The model can preview or apply semantic changes while preserving symbol identity across overloads, files, and projects.
Try it locally in the Glider playground
| Name | Type | Required | Description |
|---|---|---|---|
| typeName | string | Yes | Type name to move (simple or fully qualified). |
| targetFilePath | string | No | Optional target file path. |
| targetNamespace | string | No | Optional target namespace. |
| projectName | string | No | Optional project name to limit symbol search. |
| applyChanges | boolean | No | If true (default), applies changes to disk. If false, returns a preview diff. |
| formatAfter | boolean | No | Format changed documents after the move. Default is false. |
| organizeUsingsAfter | boolean | No | Organize usings in changed documents after the move. Default is false. |
| includeDiff | boolean | No | Include unified diff in response. Default is true. |
| maxDiffChars | number | No | Max diff characters. Use 0 for unlimited. Default is 50000. |
| includePerFileDiff | boolean | No | Include per-file diffs in changedFiles. Default is true. |
| pathStyle | string | No | Path style: 'absolute' (default) or 'relative' (to solution root). |
Move a type to a new namespace
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "move_type",
"arguments": {
"typeName": "MyClass",
"targetNamespace": "MyApp.Utils"
}
}
}{
"success": true,
"data": {
"symbolName": "MyClass",
"symbolKind": "Class",
"sourceLocation": "/path/to/OldFile.cs",
"targetLocation": "/path/to/NewFile.cs",
"filesChanged": 3,
"filesCreated": 1,
"applied": true,
"unifiedDiff": "...",
"workspaceUpdate": {
"kind": "reloaded_not_included",
"updated": false,
"inWorkspaceBefore": false,
"inWorkspaceAfter": false,
"message": "The move wrote 1 file(s) that no project compiles, so the moved code builds nowhere. ..."
}
},
"error": null
}Returns a unified diff of the change set. workspaceUpdate reports what the workspace did with a file the move created, and is null when it created none. kind reloaded_not_included means the file was written but no project compiles it, so the moved code builds nowhere. Its message names each such file and why.