csharp-refactor

Refactors C# code by applying SOLID principles, design patterns, and modern syntax.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill csharp-refactor-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-refactor
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/csharp-refactor
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill csharp-refactor-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Legacy or hastily written C# code often accumulates code smells, violates SOLID principles, and uses outdated syntax, making it hard to maintain. This Skill systematically analyzes C# files and applies targeted refactorings while preserving existing behavior. ## Core Features & Use Cases - SOLID Refactoring: Detects violations of SRP, OCP, LSP, ISP, and DIP, then applies fixes such as extracting classes, splitting interfaces, and introducing dependency injection. - Design Pattern Introduction: Maps common code smells to patterns like Builder, Strategy, Facade, Decorator, and Chain of Responsibility. - Modern C# Syntax Upgrades: Reads the TargetFramework from the .csproj file and only suggests features supported by that version, such as primary constructors, collection expressions, switch expressions, and record types. - Use Case: Point the Skill at a legacy service class with long methods and switch statements; it extracts focused methods, replaces conditionals with a Strategy pattern, and modernizes syntax, then reports every change with before/after code. ## Quick Start Ask the assistant to refactor the file OrderService.cs using all refactoring categories and report the applied changes.

Frequently Asked Questions about csharp-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor C# code to follow SOLID principles?

Run the Skill with the solid refactoring type on a target .cs file. It detects violations such as oversized classes or fat interfaces and applies fixes like Extract Class, interface segregation, and dependency injection while preserving behavior.

How to modernize legacy C# code to newer syntax?

Use the modern refactoring type, which upgrades code to features like primary constructors, collection expressions, switch expressions, and record types. The Skill reads your .csproj TargetFramework first and only proposes features your C# version supports.

Does C# refactoring work on older .NET Framework projects?

Yes, but with constraints. If the TargetFramework is below net8.0, the Skill excludes C# 12-only features such as primary constructors and collection expressions, and prints a warning note about the limitation.

Can refactoring introduce design patterns automatically?

Yes, the pattern category maps code smells to patterns: complex object creation becomes Builder or Factory Method, type-based conditionals become Strategy or State, and request pipelines become Chain of Responsibility.

What happens if no C# files are found for refactoring?

The Skill prints a message stating that no .cs files are available and stops. If a specified target file is missing, it asks you to reconfirm the file path before proceeding.

Does refactoring change the behavior of my C# code?

No, the Skill follows a behavior-preservation guideline and applies incremental changes rather than large rewrites. If a test project exists, it runs dotnet test afterward to confirm no regressions occurred.